diff options
author | 卜部昌平 <[email protected]> | 2019-10-07 16:56:08 +0900 |
---|---|---|
committer | 卜部昌平 <[email protected]> | 2019-10-09 12:12:28 +0900 |
commit | 7e0ae1698d4db0baec858a46de8d1ae875360cf5 (patch) | |
tree | 646fbe720b13469679973060b8ab5299cf076236 /iseq.c | |
parent | a220410be70264a0e4089c4d63a9c22dd688ca7c (diff) |
avoid overflow in integer multiplication
This changeset basically replaces `ruby_xmalloc(x * y)` into
`ruby_xmalloc2(x, y)`. Some convenient functions are also
provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates
x * y + z byes.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2540
Diffstat (limited to 'iseq.c')
-rw-r--r-- | iseq.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -3391,7 +3391,10 @@ succ_index_table_create(int max_pos, int *data, int size) { const int imm_size = (max_pos < IMMEDIATE_TABLE_SIZE ? max_pos + 8 : IMMEDIATE_TABLE_SIZE) / 9; const int succ_size = (max_pos < IMMEDIATE_TABLE_SIZE ? 0 : (max_pos - IMMEDIATE_TABLE_SIZE + 511)) / 512; - struct succ_index_table *sd = ruby_xcalloc(imm_size * sizeof(uint64_t) + succ_size * sizeof(struct succ_dict_block), 1); /* zero cleared */ + struct succ_index_table *sd = + rb_xcalloc_mul_add_mul( + imm_size, sizeof(uint64_t), + succ_size, sizeof(struct succ_dict_block)); int i, j, k, r; r = 0; @@ -3426,7 +3429,7 @@ succ_index_table_invert(int max_pos, struct succ_index_table *sd, int size) { const int imm_size = (max_pos < IMMEDIATE_TABLE_SIZE ? max_pos + 8 : IMMEDIATE_TABLE_SIZE) / 9; const int succ_size = (max_pos < IMMEDIATE_TABLE_SIZE ? 0 : (max_pos - IMMEDIATE_TABLE_SIZE + 511)) / 512; - unsigned int *positions = ruby_xmalloc(sizeof(unsigned int) * size), *p; + unsigned int *positions = ALLOC_N(unsigned int, size), *p; int i, j, k, r = -1; p = positions; for (j = 0; j < imm_size; j++) { |