From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E39433858D1E; Tue, 24 Jan 2023 14:01:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E39433858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674568867; bh=qV/WnihFURDga5K5FDP4liu3uzUXoh7NzXpm6L4pdw8=; h=From:To:Subject:Date:From; b=kaabbxF3tLLalmf8/QgpVteCAVx/x5afdBVChs6p6jCbBfT5N2H3+Bp4UJNdW547C /IVyJVd8xr+QU1RRBLlaOaq6zOsoEBgKBsx1TSvyYazmVRcjiJeWfKkfzRDSl7I76R phia5SjDIV5D0HWutTkI/wdVoGfWBKlbta6a7XgI= From: "aaron at aarongraham dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108518] New: Format-overflow warning using `*.s` directive with null but zero-length string Date: Tue, 24 Jan 2023 14:01:07 +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: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: aaron at aarongraham 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108518 Bug ID: 108518 Summary: Format-overflow warning using `*.s` directive with null but zero-length string Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: aaron at aarongraham dot com Target Milestone: --- https://godbolt.org/z/YGra91Woa #include int main() { // This causes a format-overflow warning, but it // should not warn if size() is 0 printf("%.*s\n", 0, (char*)0); } The warning is: : In function 'int main()': :6:13: warning: '%.*s' directive argument is null [-Wformat-overflo= w=3D] 6 | printf("%.*s\n", 0, (char*)0); | ^~~~ I see this commonly when using std::string_view with printf. In cases where= it knows that you're passing a default-constructed string_view it produces this warning. It should not produce this warning if the length being printed is 0.=