bison-patches
[Top][All Lists]
Advanced

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

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


From: Frank Heckenbach
Subject: [patch #9620] spurious compiler warning: "potential null pointer dereference"
Date: Wed, 18 Apr 2018 03:54:37 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0

URL:
  <http://savannah.gnu.org/patch/?9620>

                 Summary: spurious compiler warning: "potential null pointer
dereference"
                 Project: bison
            Submitted by: frank
            Submitted on: Wed 18 Apr 2018 07:54:36 AM UTC
                Category: None
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

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




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Wed 18 Apr 2018 07:54:36 AM UTC  Name: null-dereference-warning.patch 
Size: 3KiB   By: frank

<http://savannah.gnu.org/patch/download.php?file_id=43966>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/patch/?9620>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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