From 9bb6f0b3314d438e93ec79ae763ac57a559284bc Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 20 Oct 2012 03:32:02 +0900 Subject: pool string need not to convert --- src/dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dump.c') diff --git a/src/dump.c b/src/dump.c index 516374cd9..c8f92ec72 100644 --- a/src/dump.c +++ b/src/dump.c @@ -354,9 +354,9 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) break; case MRB_TT_STRING: - str = mrb_string_value( mrb, &irep->pool[pool_no]); + str = irep->pool[pool_no]; len = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); - if ( len > buf_size - 1) { + if (len > buf_size - 1) { buf_size = len + 1; if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == 0) goto error_exit; -- cgit v1.2.3 From 2ab40b4dccb0be468d1ee7e5e8e1b0e294e3826d Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Mon, 22 Oct 2012 10:52:24 +0900 Subject: Fix prototype/declaration mismatch in uint8_dump(). --- src/dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dump.c') diff --git a/src/dump.c b/src/dump.c index c8f92ec72..4f672e188 100644 --- a/src/dump.c +++ b/src/dump.c @@ -76,7 +76,7 @@ static int mrb_write_irep(mrb_state*,int,char*); static inline int -uint8_dump(unsigned char bin, char *hex, int type) +uint8_dump(uint8_t bin, char *hex, int type) { if (type == DUMP_TYPE_BIN) { *hex = bin; -- cgit v1.2.3 From fed285d1945d1fa3104b441cf51db2d7118a5d01 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Mon, 22 Oct 2012 11:17:31 +0900 Subject: Use MRB_DUMP_SIZE_OF_CHAR instead of sizeof(char). --- include/mruby/dump.h | 1 + src/dump.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/dump.c') diff --git a/include/mruby/dump.h b/include/mruby/dump.h index 0826606e9..cad797275 100644 --- a/include/mruby/dump.h +++ b/include/mruby/dump.h @@ -41,6 +41,7 @@ int mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname); #define MRB_DUMP_SIZE_OF_LONG 4 #define MRB_DUMP_SIZE_OF_INT 4 #define MRB_DUMP_SIZE_OF_SHORT 2 +#define MRB_DUMP_SIZE_OF_CHAR 1 /* null symbol length */ #define MRB_DUMP_NULL_SYM_LEN 0xFFFF diff --git a/src/dump.c b/src/dump.c index c8f92ec72..e7e1a4807 100644 --- a/src/dump.c +++ b/src/dump.c @@ -84,7 +84,7 @@ uint8_dump(unsigned char bin, char *hex, int type) *hex++ = bin2hex[(bin >> 4) & 0x0f]; *hex = bin2hex[bin & 0x0f]; } - return DUMP_SIZE(sizeof(char), type); + return DUMP_SIZE(MRB_DUMP_SIZE_OF_CHAR, type); } static inline int -- cgit v1.2.3 From dd10048094b3fa9a53b1385bd16ffcc07d35e1a6 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Mon, 22 Oct 2012 11:21:04 +0900 Subject: Remove redundant sizeof(char). "Always sizeof(char) == 1" is described in ISO C specs. --- src/dump.c | 4 ++-- src/string.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/dump.c') diff --git a/src/dump.c b/src/dump.c index e7e1a4807..c18362233 100644 --- a/src/dump.c +++ b/src/dump.c @@ -188,7 +188,7 @@ get_irep_header_size(mrb_state *mrb, mrb_irep *irep, int type) { uint32_t size = 0; - size += sizeof(char) * 2; + size += 2; size += DUMP_SIZE(MRB_DUMP_SIZE_OF_SHORT, type) * 4; return size; @@ -215,7 +215,7 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep, int type) char buf[32]; size += MRB_DUMP_SIZE_OF_LONG; /* plen */ - size += irep->plen * sizeof(char); /* tt(n) */ + size += irep->plen; /* tt(n) */ size += irep->plen * MRB_DUMP_SIZE_OF_SHORT; /* len(n) */ size += MRB_DUMP_SIZE_OF_SHORT; /* crc */ size = DUMP_SIZE(size, type); diff --git a/src/string.c b/src/string.c index 57bbbc831..11e760ca1 100644 --- a/src/string.c +++ b/src/string.c @@ -2494,7 +2494,7 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) if (badcheck) goto bad; return mrb_fixnum_value(0); } - len *= strlen(str)*sizeof(char); + len *= strlen(str); val = strtoul((char*)str, &end, base); @@ -2546,7 +2546,7 @@ mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck) char *p = (char *)mrb_malloc(mrb, len+1); //MEMCPY(p, s, char, len); - memcpy(p, s, sizeof(char)*len); + memcpy(p, s, len); p[len] = '\0'; s = p; } @@ -2682,7 +2682,7 @@ mrb_str_to_dbl(mrb_state *mrb, mrb_value str, int badcheck) if (s[len]) { /* no sentinel somehow */ char *p = (char *)mrb_malloc(mrb, len+1); - memcpy(p, s, sizeof(char)*len); + memcpy(p, s, len); p[len] = '\0'; s = p; } -- cgit v1.2.3 From 15f46a1feba74cba4f25ec99df79a3f1e07b0b09 Mon Sep 17 00:00:00 2001 From: Yuichiro MASUI Date: Sat, 27 Oct 2012 14:26:50 +0900 Subject: define convert method mrb_int/mrb_float with C string --- include/mrbconf.h | 9 ++++++++- src/codegen.c | 4 ++-- src/dump.c | 8 ++++---- src/load.c | 4 ++-- src/numeric.c | 10 +++++----- 5 files changed, 21 insertions(+), 14 deletions(-) (limited to 'src/dump.c') diff --git a/include/mrbconf.h b/include/mrbconf.h index 76c1b37f9..841ef1823 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -55,19 +55,26 @@ #ifdef MRB_USE_FLOAT typedef float mrb_float; +#define mrb_float_to_str(buf, i) sprintf((buf), "%.7e", (i)) +#define str_to_mrb_float(buf) (mrb_float)strtof((buf),NULL) #else typedef double mrb_float; +#define mrb_float_to_str(buf, i) sprintf((buf), "%.16e", (i)) +#define str_to_mrb_float(buf) (mrb_float)strtod((buf),NULL) #endif -#define readfloat(p) (mrb_float)strtod((p),NULL) #ifdef MRB_NAN_BOXING typedef int32_t mrb_int; #define MRB_INT_MIN INT32_MIN #define MRB_INT_MAX INT32_MAX +#define mrb_int_to_str(buf, i) sprintf((buf), "%d", (i)) +#define str_to_mrb_int(buf) (mrb_int)strtol((buf), NULL, 10); #else typedef int mrb_int; #define MRB_INT_MIN INT_MIN #define MRB_INT_MAX INT_MAX +#define mrb_int_to_str(buf, i) sprintf((buf), "%d", (i)) +#define str_to_mrb_int(buf) (mrb_int)strtol((buf), NULL, 10); #endif typedef short mrb_sym; diff --git a/src/codegen.c b/src/codegen.c index 2d01ed701..9bba9de71 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1738,7 +1738,7 @@ codegen(codegen_scope *s, node *tree, int val) case NODE_FLOAT: if (val) { char *p = (char*)tree; - mrb_float f = readfloat(p); + mrb_float f = str_to_mrb_float(p); int off = new_lit(s, mrb_float_value(f)); genop(s, MKOP_ABx(OP_LOADL, cursp(), off)); @@ -1754,7 +1754,7 @@ codegen(codegen_scope *s, node *tree, int val) case NODE_FLOAT: { char *p = (char*)tree; - mrb_float f = readfloat(p); + mrb_float f = str_to_mrb_float(p); int off = new_lit(s, mrb_float_value(-f)); genop(s, MKOP_ABx(OP_LOADL, cursp(), off)); diff --git a/src/dump.c b/src/dump.c index 15e11153e..5100014d9 100644 --- a/src/dump.c +++ b/src/dump.c @@ -226,11 +226,11 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep, int type) switch (mrb_type(irep->pool[pool_no])) { case MRB_TT_FIXNUM: - len = sprintf( buf, "%d", mrb_fixnum(irep->pool[pool_no])); + len = mrb_int_to_str( buf, mrb_fixnum(irep->pool[pool_no])); size += (uint32_t)len; break; case MRB_TT_FLOAT: - len = sprintf( buf, "%.16e", mrb_float(irep->pool[pool_no])); + len = mrb_float_to_str( buf, mrb_float(irep->pool[pool_no])); size += (uint32_t)len; break; case MRB_TT_STRING: @@ -346,11 +346,11 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) switch (mrb_type(irep->pool[pool_no])) { case MRB_TT_FIXNUM: - len = sprintf(char_buf, "%d", mrb_fixnum(irep->pool[pool_no])); + len = mrb_int_to_str(char_buf, mrb_fixnum(irep->pool[pool_no])); break; case MRB_TT_FLOAT: - len = sprintf(char_buf, "%.16e", mrb_float(irep->pool[pool_no])); + len = mrb_float_to_str(char_buf, mrb_float(irep->pool[pool_no])); break; case MRB_TT_STRING: diff --git a/src/load.c b/src/load.c index a2ae4100b..1575ffb4d 100644 --- a/src/load.c +++ b/src/load.c @@ -405,12 +405,12 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 switch (tt) { //pool data case MRB_TT_FIXNUM: - fix_num = strtol(buf, NULL, 10); + fix_num = str_to_mrb_int(buf); irep->pool[i] = mrb_fixnum_value(fix_num); break; case MRB_TT_FLOAT: - f = readfloat(buf); + f = str_to_mrb_float(buf); irep->pool[i] = mrb_float_value(f); break; diff --git a/src/numeric.c b/src/numeric.c index 102e52827..c1491ac51 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -246,8 +246,8 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float * mrb_float div, mod; if (y == 0.0) { - *divp = strtod("inf", NULL); - *modp = strtod("nan", NULL); + *divp = str_to_mrb_float("inf"); + *modp = str_to_mrb_float("nan"); return; } mod = fmod(x, y); @@ -778,7 +778,7 @@ fix_mod(mrb_state *mrb, mrb_value x) mrb_int mod; if (mrb_fixnum(y) == 0) { - return mrb_float_value(strtod("nan", NULL)); + return mrb_float_value(str_to_mrb_float("nan")); } fixdivmod(mrb, a, mrb_fixnum(y), 0, &mod); return mrb_fixnum_value(mod); @@ -807,8 +807,8 @@ fix_divmod(mrb_state *mrb, mrb_value x) mrb_int div, mod; if (mrb_fixnum(y) == 0) { - return mrb_assoc_new(mrb, mrb_float_value(strtod("inf", NULL)), - mrb_float_value(strtod("nan", NULL))); + return mrb_assoc_new(mrb, mrb_float_value(str_to_mrb_float("inf")), + mrb_float_value(str_to_mrb_float("nan"))); } fixdivmod(mrb, mrb_fixnum(x), mrb_fixnum(y), &div, &mod); return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod)); -- cgit v1.2.3 From 94d16805a53487a45e30cb275a9f55f9f8054669 Mon Sep 17 00:00:00 2001 From: Akira Yumiyama Date: Sat, 27 Oct 2012 17:12:32 +0900 Subject: fixes *.mrb dump/load format with escaped character. - hex-style string support - mrb format changes like: - "\n" (before: \n -> after: \n) - '\n' (before: \n -> after: \\n) --- src/dump.c | 28 +++++++++++++++++++++++----- src/load.c | 19 ++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) (limited to 'src/dump.c') diff --git a/src/dump.c b/src/dump.c index 5100014d9..628550df6 100644 --- a/src/dump.c +++ b/src/dump.c @@ -6,6 +6,7 @@ #include #include "mruby/dump.h" +#include #include "mruby/string.h" #ifdef ENABLE_REGEXP @@ -119,13 +120,16 @@ uint32_dump(uint32_t bin, char *hex, int type) } } +#define CHAR_ESC_LEN 13 /* sizeof(\x{ hex of 32bit unsigned int } \0) */ + static char* str_dump(char *str, char *hex, uint16_t len, int type) { if (type == DUMP_TYPE_BIN) memcpy(hex, str, len); else { - char *src, *dst; + char *src, *dst, buf[CHAR_ESC_LEN + 1]; + int n; for (src = str, dst = hex; len > 0; src++, dst++, len--) { switch (*src) { @@ -136,11 +140,19 @@ str_dump(char *str, char *hex, uint16_t len, int type) case 0x0B:/* VT */ *dst++ = '\\'; *dst = 'v'; break; case 0x0C:/* FF */ *dst++ = '\\'; *dst = 'f'; break; case 0x0D:/* CR */ *dst++ = '\\'; *dst = 'r'; break; + case 0x5C:/* \ */ *dst++ = '\\'; *dst = '\\'; break; case 0x22:/* " */ /* fall through */ case 0x27:/* ' */ /* fall through */ // case 0x3F:/* ? */ /* fall through */ - case 0x5C:/* \ */ /* fall through */ - default: *dst = *src; break; + default: + if (*src >= ' ' && *src <= '~') { + *dst = *src; + } else { + n = sprintf(buf, "\\%03o", *src & 0377); + memcpy(dst, buf, n); + dst += (n-1); + } + break; } } } @@ -167,15 +179,21 @@ str_dump_len(char *str, uint16_t len, int type) case 0x0B:/* VT */ /* fall through */ case 0x0C:/* FF */ /* fall through */ case 0x0D:/* CR */ /* fall through */ + case 0x5C:/* \ */ /* fall through */ dump_len += 2; break; case 0x22:/* " */ /* fall through */ case 0x27:/* ' */ /* fall through */ // case 0x3F:/* ? */ /* fall through */ - case 0x5C:/* \ */ /* fall through */ default: - dump_len++; break; + if (*src >= ' ' && *src <= '~') { + dump_len++; + } else { + // dump_len += sprintf(buf, "\\%03o", *src & 0377); + dump_len += 4; + } + break; } } } diff --git a/src/load.c b/src/load.c index 4d26b02ca..61fdeed8a 100644 --- a/src/load.c +++ b/src/load.c @@ -611,8 +611,8 @@ hex_to_uint32(unsigned char *hex) static char* hex_to_str(char *hex, char *str, uint16_t *str_len) { - char *src, *dst; - int escape = 0; + char *src, *dst, buf[4]; + int escape = 0, base = 0; *str_len = 0; for (src = hex, dst = str; *src != '\0'; src++) { @@ -629,7 +629,20 @@ hex_to_str(char *hex, char *str, uint16_t *str_len) case '\'': /* fall through */ case '\?': /* fall through */ case '\\': *dst++ = *src; break; - default:break; + default: + if (*src >= '0' && *src <= '7') { + base = 8; + strncpy(buf, src, 3); + } else if (*src == 'x' || *src == 'X') { + base = 16; + src++; + strncpy(buf, src, 2); + } + + char *err_ptr; + *dst++ = (unsigned char) strtol(buf, &err_ptr, base) & 0xff; + src += (err_ptr - buf - 1); + break; } escape = 0; } else { -- cgit v1.2.3 From 30f7a93d415722ec070447d573355b2c67d71310 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 30 Oct 2012 14:25:00 +0900 Subject: Use NULL instead of 0. (It is not a bug fix but a cosmetic change.) --- src/cdump.c | 10 +++++----- src/dump.c | 26 +++++++++++++------------- src/load.c | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'src/dump.c') diff --git a/src/cdump.c b/src/cdump.c index c7597e12f..b43c86ee7 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -22,7 +22,7 @@ make_cdump_isec(mrb_state *mrb, int irep_no, FILE *f) int i; mrb_irep *irep = mrb->irep[irep_no]; - if (irep == 0) + if (irep == NULL) return -1; /* dump isec struct*/ @@ -103,11 +103,11 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f) char *buf = 0; size_t buf_len, str_len; - if (irep == 0) + if (irep == NULL) return -1; buf_len = MRB_CDUMP_LINE_LEN; - if ((buf = (char *)mrb_malloc(mrb, buf_len)) == 0 ) { + if ((buf = (char *)mrb_malloc(mrb, buf_len)) == NULL) { return MRB_CDUMP_GENERAL_FAILURE; } @@ -150,7 +150,7 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f) str_len = str_format_len(irep->pool[n]) + 1; if ( str_len > buf_len ) { buf_len = str_len; - if ((buf = (char *)mrb_realloc(mrb, buf, buf_len)) == 0 ) { + if ((buf = (char *)mrb_realloc(mrb, buf, buf_len)) == NULL) { return MRB_CDUMP_GENERAL_FAILURE; } } @@ -174,7 +174,7 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname) { int irep_no, irep_num; - if (mrb == 0 || n < 0 || n >= mrb->irep_len || f == 0 || initname == 0) + if (mrb == NULL || n < 0 || n >= mrb->irep_len || f == NULL || initname == NULL) return -1; irep_num = mrb->irep_len - n; diff --git a/src/dump.c b/src/dump.c index 5100014d9..bdcb739b4 100644 --- a/src/dump.c +++ b/src/dump.c @@ -335,7 +335,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) uint16_t len =0; buf_size = MRB_DUMP_DEFAULT_STR_LEN; - if ((char_buf = (char *)mrb_malloc(mrb, buf_size)) == 0) + if ((char_buf = (char *)mrb_malloc(mrb, buf_size)) == NULL) goto error_exit; buf += uint32_dump((uint32_t)irep->plen, buf, type); /* number of pool */ @@ -358,7 +358,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) len = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); if (len > buf_size - 1) { buf_size = len + 1; - if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == 0) + if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == NULL) goto error_exit; memset(char_buf, 0, buf_size); } @@ -371,7 +371,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) len = str_dump_len(RSTRING_PTR(str), RSTRING_LEN(str), type); if ( len > buf_size - 1) { buf_size = len + 1; - if ((char_buf = mrb_realloc(mrb, char_buf, buf_size)) == 0) + if ((char_buf = mrb_realloc(mrb, char_buf, buf_size)) == NULL) goto error_exit; memset(char_buf, 0, buf_size); } @@ -405,7 +405,7 @@ write_syms_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) uint16_t buf_size =0; buf_size = MRB_DUMP_DEFAULT_STR_LEN; - if ((char_buf = (char *)mrb_malloc(mrb, buf_size)) == 0) + if ((char_buf = (char *)mrb_malloc(mrb, buf_size)) == NULL) goto error_exit; buf += uint32_dump((uint32_t)irep->slen, buf, type); /* number of symbol */ @@ -421,7 +421,7 @@ write_syms_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type) nlen = str_dump_len((char*)name, len, type); if ( nlen > buf_size - 1) { buf_size = nlen + 1; - if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == 0) + if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == NULL) goto error_exit; } memset(char_buf, 0, buf_size); @@ -457,7 +457,7 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section) default: return MRB_DUMP_GENERAL_FAILURE; } - if ((buf = (char *)mrb_calloc(mrb, 1, buf_size)) == 0) + if ((buf = (char *)mrb_calloc(mrb, 1, buf_size)) == NULL) return MRB_DUMP_GENERAL_FAILURE; buf_top = buf; @@ -542,7 +542,7 @@ write_irep_record(mrb_state *mrb, int irep_no, char* bin, uint32_t *rlen, int ty mrb_irep *irep = mrb->irep[irep_no]; int section; - if (irep == 0) + if (irep == NULL) return MRB_DUMP_INVALID_IREP; /* buf alloc */ @@ -586,7 +586,7 @@ dump_irep_record(mrb_state *mrb, int irep_no, FILE* fp, uint32_t *rlen) char *buf; mrb_irep *irep = mrb->irep[irep_no]; - if (irep == 0) + if (irep == NULL) return MRB_DUMP_INVALID_IREP; /* buf alloc */ @@ -594,7 +594,7 @@ dump_irep_record(mrb_state *mrb, int irep_no, FILE* fp, uint32_t *rlen) if (irep_record_size == 0) return MRB_DUMP_GENERAL_FAILURE; - if ((buf = (char *)mrb_calloc(mrb, 1, irep_record_size)) == 0) + if ((buf = (char *)mrb_calloc(mrb, 1, irep_record_size)) == NULL) return MRB_DUMP_GENERAL_FAILURE; if ((rc = write_irep_record(mrb, irep_no, buf, rlen, DUMP_TYPE_HEX)) != MRB_DUMP_OK) { @@ -620,7 +620,7 @@ mrb_write_irep(mrb_state *mrb, int top, char *bin) int irep_no; char *bin_top; - if (mrb == 0 || top < 0 || top >= mrb->irep_len || bin == 0) + if (mrb == NULL || top < 0 || top >= mrb->irep_len || bin == NULL) return MRB_DUMP_INVALID_ARGUMENT; bin_top = bin; @@ -648,7 +648,7 @@ mrb_dump_irep(mrb_state *mrb, int top, FILE* fp) uint32_t rlen=0; /* size of irep record */ int irep_no; - if (mrb == 0 || top < 0 || top >= mrb->irep_len || fp == 0) + if (mrb == NULL || top < 0 || top >= mrb->irep_len || fp == NULL) return MRB_DUMP_INVALID_ARGUMENT; if (fwrite(&def_rite_file_header, sizeof(rite_file_header), 1, fp) != 1) /* dummy write */ @@ -678,7 +678,7 @@ mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname) int buf_size = 0; int buf_idx = 0; - if (mrb == 0 || n < 0 || n >= mrb->irep_len || f == 0 || initname == 0) + if (mrb == NULL || n < 0 || n >= mrb->irep_len || f == NULL || initname == NULL) return -1; buf_size = sizeof(rite_binary_header) + MRB_DUMP_SIZE_OF_SHORT/* crc */; @@ -686,7 +686,7 @@ mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname) buf_size += get_irep_record_size(mrb, irep_no, DUMP_TYPE_BIN); buf_size += MRB_DUMP_SIZE_OF_LONG; /* end of file */ - if ((buf = (char *)mrb_malloc(mrb, buf_size)) == 0) + if ((buf = (char *)mrb_malloc(mrb, buf_size)) == NULL) return MRB_DUMP_GENERAL_FAILURE; rc = mrb_write_irep(mrb, n, buf); diff --git a/src/load.c b/src/load.c index 4d26b02ca..a31ef98a8 100644 --- a/src/load.c +++ b/src/load.c @@ -143,7 +143,7 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_ uint16_t buf_size =0; buf_size = MRB_DUMP_DEFAULT_STR_LEN; - if ((char_buf = (char *)mrb_malloc(mrb, buf_size)) == 0) + if ((char_buf = (char *)mrb_malloc(mrb, buf_size)) == NULL) goto error_exit; pStart = dst; @@ -192,7 +192,7 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_ if ( pdl > buf_size - 1) { buf_size = pdl + 1; - if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == 0) + if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == NULL) goto error_exit; } memset(char_buf, '\0', buf_size); @@ -219,7 +219,7 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_ if ( snl > buf_size - 1) { buf_size = snl + 1; - if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == 0) + if ((char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size)) == NULL) goto error_exit; } memset(char_buf, '\0', buf_size); -- cgit v1.2.3