Skip to content

Commit

Permalink
dump.c: fix a bug in dump data size of BIGINT pool.
Browse files Browse the repository at this point in the history
Was dumping extra NUL (\0) after the data.
  • Loading branch information
matz committed Apr 9, 2022
1 parent a252893 commit f33537f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ get_pool_block_size(mrb_state *mrb, const mrb_irep *irep)
{
mrb_int len = irep->pool[pool_no].u.str[0];
mrb_assert_int_fit(mrb_int, len, size_t, SIZE_MAX);
size += sizeof(uint8_t);
size += (size_t)len+2;
}
break;
Expand Down Expand Up @@ -199,7 +198,6 @@ write_pool_block(mrb_state *mrb, const mrb_irep *irep, uint8_t *buf)
len = irep->pool[pool_no].u.str[0];
memcpy(cur, irep->pool[pool_no].u.str, (size_t)len+2);
cur += len+2;
*cur++ = '\0';
break;

case IREP_TT_FLOAT:
Expand Down
10 changes: 5 additions & 5 deletions src/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, const uint8_t *end, size_
#endif

case IREP_TT_BIGINT:
pool_data_len = bin_to_uint8(src); /* pool data length */
pool_data_len = bin_to_uint8(src) + 2; /* pool data length */
if (src + pool_data_len > end) return FALSE;
{
else {
char *p;
pool[i].tt = IREP_TT_BIGINT;
p = (char*)mrb_malloc(mrb, pool_data_len+2);
memcpy(p, src, pool_data_len+2);
p = (char*)mrb_malloc(mrb, pool_data_len);
memcpy(p, src, pool_data_len);
pool[i].u.str = (const char*)p;
}
src += pool_data_len + 2;
src += pool_data_len;
break;

case IREP_TT_FLOAT:
Expand Down

0 comments on commit f33537f

Please sign in to comment.