[PATCH v2 5/5] avoid -Wuse-after-free [BZ #26779]

Martin Sebor msebor@gmail.com
Tue Jan 25 00:58:20 GMT 2022


On 1/24/22 17:52, Martin Sebor wrote:
> This is a repost of the original patch but broken down by source
> file and with some suppression done by #pragma GCC diagnostic
> instead of conversion to intptr_t.  It also adds fixes for
> the same problem in the test suite that I overlooked before.

The attached patch suppresses the -Wuse-after-free instance in
the testsuite.

> 
> On 1/15/22 17:21, Martin Sebor wrote:
>> GCC 12 features a couple of new warnings designed to detect uses
>> of pointers made invalid by the pointees lifetimes having ended.
>> Building Glibc with the enhanced GCC exposes a few such uses,
>> mostly after successful calls to realloc.  The attached patch
>> avoids the new warnings by converting the pointers to uintptr_t
>> first and using the converted integers instead.
>>
>> The patch suppresses all instances of the warning at the strictest
>> setting (-Wuse-after-free=3), which includes even uses in equality
>> expressions.  The default setting approved for GCC 12 is
>> -Wuse-after-free=2, which doesn't warn on such uses to accommodate
>> the pointer-adjustment-after-realloc idiom.  At the default setting,
>> the changes to ldconfig.c and setenv are not necessary.
>>
>> Martin
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc-26779-5.diff
Type: text/x-patch
Size: 4528 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20220124/5a25b06c/attachment-0001.bin>


More information about the Libc-alpha mailing list