Commit 611cf71a authored by Masaki Muranaka's avatar Masaki Muranaka

Use mrb_calloc if you want zero cleard buffers.

parent 15ac09f8
...@@ -46,8 +46,7 @@ ary_new_capa(mrb_state *mrb, int capa) ...@@ -46,8 +46,7 @@ ary_new_capa(mrb_state *mrb, int capa)
} }
a = (struct RArray*)mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class); a = (struct RArray*)mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class);
a->ptr = mrb_malloc(mrb, blen); a->ptr = mrb_calloc(mrb, blen, 1);
memset(a->ptr, 0, blen);
a->aux.capa = capa; a->aux.capa = capa;
a->len = 0; a->len = 0;
......
...@@ -460,11 +460,10 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section) ...@@ -460,11 +460,10 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
default: return MRB_DUMP_GENERAL_FAILURE; default: return MRB_DUMP_GENERAL_FAILURE;
} }
if ((buf = mrb_malloc(mrb, buf_size)) == 0) if ((buf = mrb_calloc(mrb, 1, buf_size)) == 0)
return MRB_DUMP_GENERAL_FAILURE; return MRB_DUMP_GENERAL_FAILURE;
buf_top = buf; buf_top = buf;
memset(buf, 0, buf_size);
switch (section) { switch (section) {
case DUMP_IREP_HEADER: buf += write_irep_header(mrb, irep, buf, type); break; case DUMP_IREP_HEADER: buf += write_irep_header(mrb, irep, buf, type); break;
...@@ -598,11 +597,9 @@ dump_irep_record(mrb_state *mrb, int irep_no, FILE* fp, uint32_t *rlen) ...@@ -598,11 +597,9 @@ dump_irep_record(mrb_state *mrb, int irep_no, FILE* fp, uint32_t *rlen)
if (irep_record_size == 0) if (irep_record_size == 0)
return MRB_DUMP_GENERAL_FAILURE; return MRB_DUMP_GENERAL_FAILURE;
if ((buf = mrb_malloc(mrb, irep_record_size)) == 0) if ((buf = mrb_calloc(mrb, 1, irep_record_size)) == 0)
return MRB_DUMP_GENERAL_FAILURE; return MRB_DUMP_GENERAL_FAILURE;
memset( buf, 0, irep_record_size);
if ((rc = write_irep_record(mrb, irep_no, buf, rlen, DUMP_TYPE_HEX)) != MRB_DUMP_OK) { if ((rc = write_irep_record(mrb, irep_no, buf, rlen, DUMP_TYPE_HEX)) != MRB_DUMP_OK) {
rc = MRB_DUMP_GENERAL_FAILURE; rc = MRB_DUMP_GENERAL_FAILURE;
goto error_exit; goto error_exit;
......
...@@ -246,12 +246,10 @@ unlink_free_heap_page(mrb_state *mrb, struct heap_page *page) ...@@ -246,12 +246,10 @@ unlink_free_heap_page(mrb_state *mrb, struct heap_page *page)
static void static void
add_heap(mrb_state *mrb) add_heap(mrb_state *mrb)
{ {
struct heap_page *page = mrb_malloc(mrb, sizeof(struct heap_page)); struct heap_page *page = mrb_calloc(mrb, 1, sizeof(struct heap_page));
RVALUE *p, *e; RVALUE *p, *e;
struct RBasic *prev = NULL; struct RBasic *prev = NULL;
memset(page, 0, sizeof(struct heap_page));
for (p = page->objects, e=p+HEAP_PAGE_SIZE; p<e; p++) { for (p = page->objects, e=p+HEAP_PAGE_SIZE; p<e; p++) {
p->as.free.tt = MRB_TT_FREE; p->as.free.tt = MRB_TT_FREE;
p->as.free.next = prev; p->as.free.next = prev;
......
...@@ -4792,8 +4792,7 @@ mrbc_context_new(mrb_state *mrb) ...@@ -4792,8 +4792,7 @@ mrbc_context_new(mrb_state *mrb)
{ {
mrbc_context *c; mrbc_context *c;
c = mrb_malloc(mrb, sizeof(mrbc_context)); c = mrb_calloc(mrb, 1, sizeof(mrbc_context));
memset(c, 0, sizeof(mrbc_context));
return c; return c;
} }
......
...@@ -76,8 +76,7 @@ mrb_add_irep(mrb_state *mrb, int idx) ...@@ -76,8 +76,7 @@ mrb_add_irep(mrb_state *mrb, int idx)
int max = 256; int max = 256;
if (idx > max) max = idx+1; if (idx > max) max = idx+1;
mrb->irep = mrb_malloc(mrb, sizeof(mrb_irep*)*max); mrb->irep = mrb_calloc(mrb, max, sizeof(mrb_irep*));
memset(mrb->irep, 0, sizeof(mrb_irep*)*max);
mrb->irep_capa = max; mrb->irep_capa = max;
} }
else if (mrb->irep_capa <= idx) { else if (mrb->irep_capa <= idx) {
......
...@@ -28,16 +28,14 @@ static void ...@@ -28,16 +28,14 @@ static void
stack_init(mrb_state *mrb) stack_init(mrb_state *mrb)
{ {
/* assert(mrb->stack == NULL); */ /* assert(mrb->stack == NULL); */
mrb->stbase = mrb_malloc(mrb, sizeof(mrb_value) * STACK_INIT_SIZE); mrb->stbase = mrb_calloc(mrb, STACK_INIT_SIZE, sizeof(mrb_value));
memset(mrb->stbase, 0, sizeof(mrb_value) * STACK_INIT_SIZE);
mrb->stend = mrb->stbase + STACK_INIT_SIZE; mrb->stend = mrb->stbase + STACK_INIT_SIZE;
mrb->stack = mrb->stbase; mrb->stack = mrb->stbase;
/* assert(mrb->ci == NULL); */ /* assert(mrb->ci == NULL); */
mrb->cibase = mrb_malloc(mrb, sizeof(mrb_callinfo)*CALLINFO_INIT_SIZE); mrb->cibase = mrb_calloc(mrb, CALLINFO_INIT_SIZE, sizeof(mrb_callinfo));
mrb->ciend = mrb->cibase + CALLINFO_INIT_SIZE; mrb->ciend = mrb->cibase + CALLINFO_INIT_SIZE;
mrb->ci = mrb->cibase; mrb->ci = mrb->cibase;
memset(mrb->ci, 0, sizeof(mrb_callinfo));
mrb->ci->target_class = mrb->object_class; mrb->ci->target_class = mrb->object_class;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment