switch(op[0]) { case '+': /* * Do the op into an unsigned to avoid overflow and then cast * back to check the resulting signage. */ temp = l + r; /// <- HERE res = (int64_t) temp; /* very simplistic check for over-& underflow */ if ((res < 0 && l > 0 && r > 0) || (res > 0 && l < 0 && r < 0)) yyerror("integer overflow or underflow occurred for " "operation '%s %s %s'", left, op, right); break; case '-': /* * Do the op into an unsigned to avoid overflow and then cast * back to check the resulting signage. */ temp = l - r; /// <- HERE res = (int64_t) temp; /* very simplistic check for over-& underflow */ if ((res < 0 && l > 0 && l > r) || (res > 0 && l < 0 && l < r) ) yyerror("integer overflow or underflow occurred for " "operation '%s %s %s'", left, op, right); break; case '/': if (r == 0) yyerror("second argument to '%s' must not be zero", op); res = l / r; /// <-- HERE, lack of handling -9223372036854775808 / -1 break; case '%': if (r == 0) yyerror("second argument to '%s' must not be zero", op); res = l % r; /// <-- HERE, lack of handling -9223372036854775808 % -1 break; case '*': /* shortcut */ if ((l == 0) || (r == 0)) { res = 0; break; } sign = 1; if (l < 0) sign *= -1; if (r < 0) sign *= -1; res = l * r; /// <- HERE [...] # eval expr '4611686018427387904 + 4611686018427387904' /public/src.git/bin/expr/expr.y:315:12: runtime error: signed integer overflow: 4611686018427387904 + 4611686018427387904 cannot be represented in type 'long'