aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorwelinder@troll.com <welinder@troll.com>2004-08-12 13:46:49 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:02:39 -0700
commit4acd15d1cce7fe8a7636b6670bb6fdc365d7f8d5 (patch)
treecae67f2873a83534e94ed8d67b9e642c095d82b9
parent3d75606ad756192825039cedc1b370f8eae3e1b7 (diff)
downloadsparse-dev-4acd15d1cce7fe8a7636b6670bb6fdc365d7f8d5.tar.gz
expand.c:
Handle integer overflow in unary minus.
-rw-r--r--expand.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/expand.c b/expand.c
index 4e516f80..1edd7d32 100644
--- a/expand.c
+++ b/expand.c
@@ -544,19 +544,28 @@ static int simplify_preop(struct expression *expr)
if (op->type != EXPR_VALUE)
return 0;
+
+ mask = 1ULL << (expr->ctype->bit_size-1);
v = op->value;
switch (expr->op) {
case '+': break;
- case '-': v = -v; break;
+ case '-':
+ if (v == mask && !(expr->ctype->ctype.modifiers & MOD_UNSIGNED))
+ goto Overflow;
+ v = -v;
+ break;
case '!': v = !v; break;
case '~': v = ~v; break;
default: return 0;
}
- mask = 1ULL << (expr->ctype->bit_size-1);
mask = mask | (mask-1);
expr->value = v & mask;
expr->type = EXPR_VALUE;
return 1;
+
+Overflow:
+ warn(expr->pos, "constant integer operation overflow");
+ return 0;
}
static int simplify_float_preop(struct expression *expr)