summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJose Narvaez <[email protected]>2014-06-13 10:09:28 +0100
committerJose Narvaez <[email protected]>2014-06-13 10:09:28 +0100
commit44a5809224e819bf8bcca4ae9a8c5ea5bf4cefd7 (patch)
tree334b72075e95bf46be92176e5e39d3792a9d8b94 /src
parentda55b5040928c69426c49b8a04541b5adf0abc1d (diff)
downloadmruby-44a5809224e819bf8bcca4ae9a8c5ea5bf4cefd7.tar.gz
mruby-44a5809224e819bf8bcca4ae9a8c5ea5bf4cefd7.zip
Fixed possible division by zero in 'codegen.c' reported by 'clang-analyzer'
Diffstat (limited to 'src')
-rw-r--r--src/codegen.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/codegen.c b/src/codegen.c
index c7b8e2d74..e2a43e5fc 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -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++;
}