[PATCH] malloc: obscure calloc use in tst-calloc
Sam James
sam@gentoo.org
Sat Jan 11 23:55:59 GMT 2025
"Maciej W. Rozycki" <macro@orcam.me.uk> writes:
> On Fri, 10 Jan 2025, Sam James wrote:
>
>> diff --git a/malloc/tst-calloc.c b/malloc/tst-calloc.c
>> index 77a32f8052..122b2cbeaf 100644
>> --- a/malloc/tst-calloc.c
>> +++ b/malloc/tst-calloc.c
>> @@ -94,16 +95,19 @@ random_test (void)
>> static void
>> null_test (void)
>> {
>> + /* Obscure allocation size from the compiler. */
>> + volatile size_t max_size = UINT_MAX;
>> + volatile size_t zero_size = 0;
>> /* If the size is 0 the result is implementation defined. Just make
>> sure the program doesn't crash. The result of calloc is
>> deliberately ignored, so do not warn about that. */
>> DIAG_PUSH_NEEDS_COMMENT;
>> DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result");
>> calloc (0, 0);
>> - calloc (0, UINT_MAX);
>> - calloc (UINT_MAX, 0);
>> - calloc (0, ~((size_t) 0));
>> - calloc (~((size_t) 0), 0);
>> + calloc (0, max_size);
>> + calloc (max_size, 0);
>> + calloc (0, ~((size_t) zero_size));
>> + calloc (~((size_t) zero_size), 0);
>
> The casts obviously serve no purpose and make no sense anymore.
I'll add that to series of other fixes I'll send later.
More information about the Libc-alpha
mailing list