diff options
| author | cremno <[email protected]> | 2014-07-09 13:51:58 +0200 |
|---|---|---|
| committer | cremno <[email protected]> | 2014-07-09 13:55:08 +0200 |
| commit | ef59f553a32fb6a3acb99c29ff198954fbe45913 (patch) | |
| tree | 5a0d9ca076be4c4565bc213bf1aafc874ea2ca7e /src/codegen.c | |
| parent | 023908afc2790f8070da13d9ab3e51677b88dcde (diff) | |
| download | mruby-ef59f553a32fb6a3acb99c29ff198954fbe45913.tar.gz mruby-ef59f553a32fb6a3acb99c29ff198954fbe45913.zip | |
invalid base shouldn't silently fail
Revert 44a5809224e819bf8bcca4ae9a8c5ea5bf4cefd7 and check range of
`base` with `mrb_assert`.
It actually can only be either 2, 8, 10 or 16 (and never 0), unless
mruby sources are modified. But I don't see a reason to impose further
limits.
Diffstat (limited to 'src/codegen.c')
| -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++; } |
