From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 321B13858412; Mon, 25 Oct 2021 18:27:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 321B13858412 From: "eyalroz1 at gmx dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/102936] New: Excessive warnings about passing NULL for an "%s" specifier Date: Mon, 25 Oct 2021 18:27:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eyalroz1 at gmx dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Oct 2021 18:27:11 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102936 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 =20 __attribute__((format(__printf__, 2, 3))) int sprintf_(char* buffer, const char* format, ...) { (void) buffer; (void) format; return 0; }=20 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 =E2=80=98%s=E2=80=99 expects argument of typ= e =E2=80=98char *=E2=80=99, but argument 3 has type =E2=80=98void *=E2=80=99 [-Wformat=3D] a.c:15:9: warning: =E2=80=98%s=E2=80=99 directive argument is null [-Wf= ormat-overflow=3D] The second warning seems legit. However - I don't think I should be getting= the first warning. If I can write: char* ptr =3D NULL; and not get a type warning, I don't see why I should get one for passing NU= LL to the function.=