mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fixed possible division by zero in 'codegen.c' reported by 'clang-analyzer'
This commit is contained in:
+15
-13
@@ -1106,21 +1106,23 @@ readint_mrb_int(codegen_scope *s, const char *p, int base, mrb_bool neg, mrb_boo
|
||||
codegen_error(s, "malformed readint input");
|
||||
}
|
||||
|
||||
if (neg) {
|
||||
if ((MRB_INT_MIN + n)/base > result) {
|
||||
*overflow = TRUE;
|
||||
return 0;
|
||||
if(base > 0) {
|
||||
if (neg) {
|
||||
if ((MRB_INT_MIN + 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;
|
||||
else {
|
||||
if ((MRB_INT_MAX - n)/base < result) {
|
||||
*overflow = TRUE;
|
||||
return 0;
|
||||
}
|
||||
result *= base;
|
||||
result += n;
|
||||
}
|
||||
result *= base;
|
||||
result += n;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user