aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2022-08-23 11:44:32 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2022-08-23 11:44:32 -0700
commitd618d8e6043e229de0358b24bc793ef10e3e041b (patch)
tree470df5b66c81ceaedf56cbda9fca3a1397dee483
parentdbaf1d1fe95efa2c2d9360a09a76e0e94b7bee85 (diff)
downloadsparse-d618d8e6043e229de0358b24bc793ef10e3e041b.tar.gz
bitwise: allow all-bits-set as a restricted value
We've always allowed zero ("no bits set") as a special case for bitwise restricted types. For the exact same reason we should allow the "all bits set" case, but it was just harder to test for, since that case wasn't just a simple constant value. The previous commit now made it a simple constant value, and we can easily handle that case too. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--evaluate.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/evaluate.c b/evaluate.c
index 5697128a..ad4db0d5 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -418,8 +418,10 @@ static int restricted_value(struct expression *v, struct symbol *type)
{
if (v->type != EXPR_VALUE)
return 1;
- if (v->value != 0)
- return 1;
+ if (v->value != 0) {
+ unsigned long long mask = bits_mask(type->bit_size);
+ return (v->value & mask) != mask;
+ }
return 0;
}