diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-07-09 23:05:01 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-07-09 23:05:01 +0900 |
| commit | 42110dcee1733c39129dbbbfe619943a9da158a8 (patch) | |
| tree | 45a8a13398549740a48b2b6622149f2a02a2eb01 /src | |
| parent | 334b1ac485bd2afa76edff729aa7def9c756414a (diff) | |
| parent | ef59f553a32fb6a3acb99c29ff198954fbe45913 (diff) | |
| download | mruby-42110dcee1733c39129dbbbfe619943a9da158a8.tar.gz mruby-42110dcee1733c39129dbbbfe619943a9da158a8.zip | |
Merge pull request #2455 from cremno/readint_mrb_int-check-base
invalid base shouldn't silently fail
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/codegen.c b/src/codegen.c index 03c752826..531cfcb11 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1095,6 +1095,7 @@ readint_mrb_int(codegen_scope *s, const char *p, int base, mrb_bool neg, mrb_boo mrb_int result = 0; int n; + mrb_assert(base >= 2 && base <= 36); if (*p == '+') p++; while (p < e) { char c = *p; @@ -1108,23 +1109,21 @@ readint_mrb_int(codegen_scope *s, const char *p, int base, mrb_bool neg, mrb_boo codegen_error(s, "malformed readint input"); } - if(base > 0) { - if (neg) { - if ((MRB_INT_MIN + n)/base > result) { - *overflow = TRUE; - return 0; - } - result *= base; - result -= n; + if (neg) { + if ((MRB_INT_MIN + n)/base > result) { + *overflow = TRUE; + return 0; } - else { - if ((MRB_INT_MAX - n)/base < result) { - *overflow = TRUE; - return 0; - } - result *= base; - result += n; + result *= base; + result -= n; + } + else { + if ((MRB_INT_MAX - n)/base < result) { + *overflow = TRUE; + return 0; } + result *= base; + result += n; } p++; } |
