[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patch #9620] spurious compiler warning: "potential null pointer der

From: Akim Demaille
Subject: Re: [patch #9620] spurious compiler warning: "potential null pointer dereference"
Date: Thu, 10 May 2018 10:51:59 +0200

> The generated parser produces a GCC warning with "-Wnull-dereference":
>  parse.cpp: error: potential null pointer dereference
> [-Werror=null-dereference]
> The reason is:
>    char const* yyformat = YY_NULLPTR;
> before it's set in a switch for cases 0 to 5. Now, this seems in fact correct
> due to "YYERROR_VERBOSE_ARGS_MAXIMUM = 5" and the way the code finally gets
> there. But that's a bit much to expect the compiler to recognize.
> Actually I do find the code rather fragile; the definition of
> YYERROR_VERBOSE_ARGS_MAXIMUM does not even have a comment pointing out the
> ramifications of changing it.

Agreed.  That’s also why actually instead of your approach, I would
prefer a `default: abort()`.

> I also find the code a bit strange at all; why have a number of format strings
> that differ only in the number of "or %s" parts, and which must all be
> translated individually? Rather than adding repeated parts in a loop, or using
> a more flexible wording such as "expecing one of the following: « ?

Because of internationalization: you don’t know how it would be
translated, how punctuation would be, etc.

> Anyway, this patch does just the minimum necessary to avoid the warning (and
> make the code more robust in case someone changes
> YYERROR_VERBOSE_ARGS_MAXIMUM), by using "default" instead of "case 0 ».

But it would be incorrect anyway.  Would `default: abort` suit you?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]