From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D94DA3858C98; Fri, 22 Mar 2024 07:07:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D94DA3858C98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711091273; bh=6phGEokx64Do+c086dJT1MVM+TKV46Lh8yS39M0I8KM=; h=From:To:Subject:Date:From; b=x9bxVfIgNqXQnbDTKR3koB4DZ7yZ6E3I9cBfGV2ZSCSvA8+DQul02a03a6Fqmstgr 0Abb/SrfdBqo49iL7W2MgTCpUbyOW3ADB3/vMZyAIFTY/P0gCAISnMX8vhuKgw6DQE kKNO5mqtGNDu6pUkTrcgp8iV0sv7Mo9RbgObP8Xs= From: "admin@tho-otto.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114430] New: False positive for -Wformat Date: Fri, 22 Mar 2024 07:07:53 +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.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: admin@tho-otto.de 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=3D114430 Bug ID: 114430 Summary: False positive for -Wformat Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: admin@tho-otto.de Target Milestone: --- Using GCC 13.2.1, with: #include struct WWPerson { char Name[12]; }; struct WWPerson WWPersons[] =3D { {"Bill R"}, {"Bill R"}, {"Barry G"}, }; char item[12 + 1]; void test() { for (size_t i =3D 0; i < sizeof(WWPersons) / sizeof(struct WWPerson); i= ++) { sprintf(item, "%s", WWPersons[i].Name); } } When compiling with -O2, i get: bla.c: In function =E2=80=98test=E2=80=99: bla.c:18:24: warning: =E2=80=98%s=E2=80=99 directive writing up to 35 bytes= into a region of size 13 [-Wformat-overflow=3D] 18 | sprintf(item, "%s", WWPersons[i].Name); | ^~ bla.c:18:9: note: =E2=80=98sprintf=E2=80=99 output between 1 and 36 bytes i= nto a destination of size 13 18 | sprintf(item, "%s", WWPersons[i].Name); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I get the same warning with version 10.5.0, but not with version 9.5.0 The warning disappears when i remove one element from the array.=