From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1EBD23856DDA; Tue, 2 Aug 2022 07:31:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EBD23856DDA From: "eb at emlix dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/106503] New: "const char []" in local scope never initialized Date: Tue, 02 Aug 2022 07:31: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: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eb at emlix 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: Tue, 02 Aug 2022 07:31:12 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106503 Bug ID: 106503 Summary: "const char []" in local scope never initialized Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: eb at emlix dot com Target Milestone: --- Given the following test program: ------------ #include #include #define WRITEL(str) \ do { \ wdata[wpos].iov_base =3D (void*)(str); \ wdata[wpos].iov_len =3D strlen(str); \ wlen +=3D wdata[wpos].iov_len; \ wpos++; \ } while (0) int main(int argc, char **argv) { struct iovec wdata[20]; unsigned int wpos =3D 0; ssize_t wlen =3D 0; int i =3D (argc > 1) ? 1 : 0; WRITEL("foo"); if (argc) { const char junk[] =3D "abc"; WRITEL(junk + i); } else { const char *junk =3D "def"; WRITEL(junk + i); } WRITEL("baz\n"); return writev(1, wdata, wpos) > 0 ? 0 : 1; } ------------ For gcc 10 and before, and gcc 11, 12, or 13 (b06a282921c71bbc5cab69bc515804bd80f55e92) when used with -O0, this outputs: $ ./Ch fooabcbaz >>From gcc 11 on when using -O1 or more it does not seem to initialize the "j= unk" buffer, so it may output random things: $ ./Ch=20 foocbaz $ ./Ch=20 foo=EF=BF=BDbaz $ ./Ch=20 foo+baz $ ./Ch=20 foo baz $ ./Ch=20 foo[baz I have seen the same behavior on both amd64 and sparc32, with distro compil= ers (openSUSE, Gentoo) as well as an unpatched gcc13 built with Gentoo ebuilds.=