[bugfix] must multiply the size by sizeof(struct) when using realloc function

This commit is contained in:
Yuichi Nishiwaki 2014-01-18 23:01:00 +09:00
parent a315f518d2
commit 1aa35891ad
2 changed files with 4 additions and 4 deletions

View File

@ -343,8 +343,8 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
#if DEBUG
puts("irep realloced");
#endif
scope->irep = (struct pic_irep **)pic_realloc(pic, scope->irep, scope->icapa * 2);
scope->icapa *= 2;
scope->irep = (struct pic_irep **)pic_realloc(pic, scope->irep, sizeof(struct pic_irep *) * scope->icapa);
}
k = scope->ilen++;
scope->code[scope->clen].insn = OP_LAMBDA;
@ -458,8 +458,8 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
}
if (scope->plen >= scope->pcapa) {
scope->pool = (pic_value *)pic_realloc(pic, scope->pool, scope->pcapa * 2);
scope->pcapa *= 2;
scope->pool = (pic_value *)pic_realloc(pic, scope->pool, sizeof(pic_value) * scope->pcapa);
}
pidx = scope->plen++;
scope->pool[pidx] = pic_car(pic, pic_cdr(pic, obj));
@ -695,8 +695,8 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
case PIC_TT_BLOB: {
int pidx;
if (scope->plen >= scope->pcapa) {
scope->pool = (pic_value *)pic_realloc(pic, scope->pool, scope->pcapa * 2);
scope->pcapa *= 2;
scope->pool = (pic_value *)pic_realloc(pic, scope->pool, sizeof(pic_value) * scope->pcapa);
}
pidx = scope->plen++;
scope->pool[pidx] = obj;

View File

@ -74,8 +74,8 @@ pic_error_with_exception_handler(pic_state *pic)
puts("rescue realloced");
#endif
pic->rescue = (struct pic_proc **)pic_realloc(pic, pic->rescue, pic->rlen * 2);
pic->rlen *= 2;
pic->rescue = (struct pic_proc **)pic_realloc(pic, pic->rescue, sizeof(struct pic_proc *) * pic->rlen);
}
pic->rescue[pic->ridx++] = handler;