On Thu, Mar 13, 2025 at 03:51:15PM +0100, Richard Biener wrote:
> On Thu, 13 Mar 2025, Jakub Jelinek wrote:
>
> > On Thu, Mar 13, 2025 at 03:44:21PM +0100, Richard Biener wrote:
> > > + case OPT_D:
> > > + case OPT_U:
> > > + if (strncmp (options[i].arg, "_FORTIFY_SOURCE",
> > > + strlen ("_FORTIFY_SOURCE")) == 0)
> >
> > I'd say you want to verify that after that substring there is either
> > '\0' or "=".
> > Otherwise you'll record -D_FORTIFY_SOURCE_NOT_REALLY=1 which doesn't
> > matter at all.
>
> I had that first and thought it wasn't worth the cycles, but I can
> surely add that (and thus also separate -U and -D handling).
If you use sizeof ("_FORTIFY_SOURCE") - 1 instead of strlen, there won't
be too many extra cycles even at -O0.
And I think it is fine to handle -U and -D together.
if (startswith (options[i].arg, "_FORTIFY_SOURCE")
&& (options[i].arg[sizeof ("_FORTIFY_SOURCE") - 1] == '\0'
|| (options[i].opt_index == OPT_D
&& options[i].arg[sizeof ("_FORTIFY_SOURCE") - 1] == '=')))
Jakub