On Tue, Sep 30, 2025 at 10:00 PM Collin Funk <[email protected]> wrote: > > Chet Ramey <[email protected]> writes: > > >> You can probably just add a check add something like: > >> if (bytes < PTRDIFF_MAX) > >> { > >> errno = ENOMEM; > >> return NULL; > >> } > >> to silence it (although I haven't tested it). > > > > I hate adding code just to silence spurious warnings. > > I don't blame you. I should have mentioned that the example was more-so > an explanation of what the warning was about. The message is not too > helpful, in my opinion. > > It seems the OP is using special compiler options (which is a perfectly > reasonable way to hunt for bugs), since I do not see these warnings by > default with GCC 15 on Fedora.
I believe this warning shows up only because gcc with -flto can notice
this code path in shell_getc where realloc gets called with a size arg
that is a constant larger than PTRDIFF_MAX:
if (shell_input_line_size > (SIZE_MAX - 256))
...
shell_input_line_size = SIZE_MAX;
shell_input_line = xrealloc (shell_input_line, shell_input_line_size);
If we are going to guard against theoretical overflow, we might as well
use the more correct allocation size limit of PTRDIFF_MAX, which will
silence this warning.
0001-parse.y-use-PTRDIFF_MAX-as-allocation-size-bound.patch
Description: Binary data
