Avoid division by zero in the preprocessor
Trac #15792
Issue=115
Signed-off-by: Daniel Koch
Author: Nicolas Capens
git-svn-id: https://angleproject.googlecode.com/svn/trunk@566 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/preprocessor/cpp.c b/src/compiler/preprocessor/cpp.c
index 03ab787..03dd4f6 100644
--- a/src/compiler/preprocessor/cpp.c
+++ b/src/compiler/preprocessor/cpp.c
@@ -468,6 +468,17 @@
val = *res;
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
token = eval(token, binop[i].prec, res, err, yylvalpp);
+
+ if (binop[i].op == op_div || binop[i].op == op_mod)
+ {
+ if (*res == 0)
+ {
+ CPPErrorToInfoLog("preprocessor divide or modulo by zero");
+ *err = 1;
+ return token;
+ }
+ }
+
*res = binop[i].op(val, *res);
}
return token;