On Wed, Feb 02, 2022 at 01:23:44PM -0700, Jeff Law via Gcc-patches wrote: > Note that I think something similar may be needed to mark EOL for the > pointer passed to realloc to fix a related set of false positives for code > like this > > bool something = p != q; > whatever = realloc (p, newsize) > if (something) > > We forward propagate the p != q test generating something like this; > > whatever - realloc (p, newsize); > if (p != q)
IMNSHO we shouldn't warn for pointer passed to realloc being used in equality comparisons at all, it is just unnecessarily pedantic, it works just fine and a lot of programs use it to find out if the memory was actually reallocated or was just extended or shrunk in place; in the former case they often need some extra work, such as adjust something in the memory block. Yes, one can probably do uintptr_t pint = (uintptr_t) p; whatever = realloc (p, newsize); if ((uintptr_t) whatever != pint) but I think most people don't bother. Jakub