public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102936] New: Excessive warnings about passing NULL for an "%s" specifier
@ 2021-10-25 18:27 eyalroz1 at gmx dot com
  2021-10-25 18:52 ` [Bug c/102936] " schwab@linux-m68k.org
  0 siblings, 1 reply; 2+ messages in thread
From: eyalroz1 at gmx dot com @ 2021-10-25 18:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102936

            Bug ID: 102936
           Summary: Excessive warnings about passing NULL for an "%s"
                    specifier
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eyalroz1 at gmx dot com
  Target Milestone: ---

Consider the following program:

    #include <stddef.h> 

    __attribute__((format(__printf__, 2, 3)))
    int sprintf_(char* buffer, const char* format, ...)
    {
        (void) buffer;
        (void) format;
        return 0;
   } 

    int main() {
        char buffer[100];
        return sprintf_(buffer, "%s", NULL);
    }

when compiled with `-W -Wall`, we get two warnings:

    a.c:15:28: warning: format ‘%s’ expects argument of type ‘char *’, but
argument 3 has type ‘void *’ [-Wformat=]
    a.c:15:9: warning: ‘%s’ directive argument is null [-Wformat-overflow=]

The second warning seems legit. However - I don't think I should be getting the
first warning. If I can write:

    char* ptr = NULL;

and not get a type warning, I don't see why I should get one for passing NULL
to the function.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/102936] Excessive warnings about passing NULL for an "%s" specifier
  2021-10-25 18:27 [Bug c/102936] New: Excessive warnings about passing NULL for an "%s" specifier eyalroz1 at gmx dot com
@ 2021-10-25 18:52 ` schwab@linux-m68k.org
  0 siblings, 0 replies; 2+ messages in thread
From: schwab@linux-m68k.org @ 2021-10-25 18:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102936

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
In varargs context no implicit type conversions are performed.  A pointer to
void may have a different representation than a pointer to char.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-25 18:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25 18:27 [Bug c/102936] New: Excessive warnings about passing NULL for an "%s" specifier eyalroz1 at gmx dot com
2021-10-25 18:52 ` [Bug c/102936] " schwab@linux-m68k.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).