diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/alloc.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/alloc.c b/tests/alloc.c index 9e6e892..382131f 100644 --- a/tests/alloc.c +++ b/tests/alloc.c @@ -3,6 +3,7 @@ #include "../src/alloc.h" #include "../src/diag.h" +#include <errno.h> #include <stdlib.h> int main(void) { @@ -13,13 +14,20 @@ int main(void) { }; bfs_verify(sizeof_flex(struct flexible, bar, 0) >= sizeof(struct flexible)); bfs_verify(sizeof_flex(struct flexible, bar, 16) % alignof(struct flexible) == 0); - bfs_verify(sizeof_flex(struct flexible, bar, SIZE_MAX / sizeof(int) + 1) - == align_floor(alignof(struct flexible), SIZE_MAX)); + + size_t too_many = SIZE_MAX / sizeof(int) + 1; + bfs_verify(sizeof_flex(struct flexible, bar, too_many) == align_floor(alignof(struct flexible), SIZE_MAX)); // Corner case: sizeof(type) > align_ceil(alignof(type), offsetof(type, member)) // Doesn't happen in typical ABIs bfs_verify(flex_size(8, 16, 4, 4, 1) == 16); + // Make sure we detect allocation size overflows + bfs_verify(ALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW); + bfs_verify(ZALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW); + bfs_verify(ALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW); + bfs_verify(ZALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW); + // varena tests struct varena varena; VARENA_INIT(&varena, struct flexible, bar); |