Skip to content

Commit

Permalink
Pass size_t instead of word values to GC_malloc in hugetest
Browse files Browse the repository at this point in the history
(refactoring)

Issue #627 (bdwgc).

* tests/huge.c (GC_WORD_MAX): Rename to SIZE_MAX; change its type from
GC_word to size_t.
* tests/huge.c (SIZE_MAX): Undefine it (before definition).
* tests/huge.c (GC_SWORD_MAX): Rename to U_SSIZE_MAX; change type from
GC_signed_word to size_t (unsigned).
* tests/huge.c (main): Rename GC_WORD_MAX to SIZE_MAX; rename
GC_SWORD_MAX to U_SSIZE_MAX.
  • Loading branch information
ivmai committed Mar 22, 2024
1 parent b37ca67 commit f746114
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/huge.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,26 @@
} \
} while (0)

#define GC_WORD_MAX ((GC_word)-1)
#define GC_SWORD_MAX ((GC_signed_word)(GC_WORD_MAX >> 1))
#undef SIZE_MAX
#define SIZE_MAX (~(size_t)0)

#define U_SSIZE_MAX (SIZE_MAX >> 1) /* unsigned */

int main(void)
{
GC_INIT();

CHECK_ALLOC_FAILED(GC_MALLOC(GC_SWORD_MAX - 1024), "SWORD_MAX-1024");
CHECK_ALLOC_FAILED(GC_MALLOC(GC_SWORD_MAX), "SWORD_MAX");
CHECK_ALLOC_FAILED(GC_MALLOC(U_SSIZE_MAX - 1024), "SSIZE_MAX-1024");
CHECK_ALLOC_FAILED(GC_MALLOC(U_SSIZE_MAX), "SSIZE_MAX");
/* Skip other checks to avoid "exceeds maximum object size" gcc warning. */
# if !defined(_FORTIFY_SOURCE)
CHECK_ALLOC_FAILED(GC_MALLOC((GC_word)GC_SWORD_MAX + 1), "SWORD_MAX+1");
CHECK_ALLOC_FAILED(GC_MALLOC((GC_word)GC_SWORD_MAX + 1024),
"SWORD_MAX+1024");
CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX - 1024), "WORD_MAX-1024");
CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX - 16), "WORD_MAX-16");
CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX - 8), "WORD_MAX-8");
CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX - 4), "WORD_MAX-4");
CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX), "WORD_MAX");
CHECK_ALLOC_FAILED(GC_MALLOC(U_SSIZE_MAX + 1), "SSIZE_MAX+1");
CHECK_ALLOC_FAILED(GC_MALLOC(U_SSIZE_MAX + 1024), "SSIZE_MAX+1024");
CHECK_ALLOC_FAILED(GC_MALLOC(SIZE_MAX - 1024), "SIZE_MAX-1024");
CHECK_ALLOC_FAILED(GC_MALLOC(SIZE_MAX - 16), "SIZE_MAX-16");
CHECK_ALLOC_FAILED(GC_MALLOC(SIZE_MAX - 8), "SIZE_MAX-8");
CHECK_ALLOC_FAILED(GC_MALLOC(SIZE_MAX - 4), "SIZE_MAX-4");
CHECK_ALLOC_FAILED(GC_MALLOC(SIZE_MAX), "SIZE_MAX");
# endif
printf("SUCCEEDED\n");
return 0;
Expand Down

0 comments on commit f746114

Please sign in to comment.