aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2024-03-24 01:20:19 -0700
committerMichael Forney <mforney@mforney.org>2024-03-24 02:41:29 -0700
commit9a34e3c5ce34662be956bdb1d0ad988316d16a94 (patch)
tree5d89786d412432ab82c680575ef423d6fe63bd10
parent7c4217eaaf28ebf52106a4b2e8b03e992fef5da0 (diff)
decl: Check alignment range
We store alignment as int, so check that it fits to avoid implementation-defined behavior. Also, fix printf format specifier and drop unneeded parentheses.
-rw-r--r--decl.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/decl.c b/decl.c
index 98ac497..0a5cf6d 100644
--- a/decl.c
+++ b/decl.c
@@ -1,4 +1,5 @@
#include <assert.h>
+#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -446,8 +447,8 @@ declspecs(struct scope *s, enum storageclass *sc, enum funcspec *fs, int *align)
expect(TLPAREN, "after 'alignas'");
other = typename(s, NULL);
i = other ? other->align : intconstexpr(s, false);
- if (i & (i - 1))
- error(&tok.loc, "invalid alignment: %d", i);
+ if (i & i - 1 || i > INT_MAX)
+ error(&tok.loc, "invalid alignment: %llu", i);
if (i > *align)
*align = i;
expect(TRPAREN, "to close 'alignas' specifier");