patchBison - Patches: patch #9620, spurious compiler warning:...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #9620: spurious compiler warning: "potential null pointer dereference"

Submitter:  Frank Heckenbach <frank>
Submitted:  Wed 18 Apr 2018 07:54:36 AM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  akim Open/Closed:  Closed

Wed 18 Apr 2018 07:54:36 AM UTC, original submission:  

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.

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: "?

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".

Frank Heckenbach <frank>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by akim (Updated the item)
  • -email is unavailable- added by frank (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-05-12 akim StatusNone Done
        Assigned toNone akim
        Open/ClosedOpen Closed
    2018-04-18 frank Attached File- Added null-dereference-warning.patch, #43966

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code