From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 486CF3858D20; Thu, 3 Feb 2022 14:55:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 486CF3858D20 From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/104369] New: False positive from -Wanalyzer-use-of-uninitialized-value with realloc moving buffer Date: Thu, 03 Feb 2022 14:55:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm 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 attachments.created 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: Thu, 03 Feb 2022 14:55:24 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104369 Bug ID: 104369 Summary: False positive from -Wanalyzer-use-of-uninitialized-value with realloc moving buffer Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Target Milestone: --- Created attachment 52343 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D52343&action=3Dedit Reduced reproducer The attached reproducer emits two false positives from -Wanalyzer-use-of-uninitialized-value, both "when 'realloc' succeeds, moving buffer", the first of which is: : In function 'main': :79:34: warning: use of uninitialized value '*pollfds.fd' [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 79 | pollfds[nsockets - 1].fd =3D accept(pollfds[0].fd, &remote, &= len); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~ 'main': events 1-7 | | 62 | if (!pollfds) { | | ^ | | | | | (1) following 'false' branch (when 'pollfds' is non-NULL)= ... |...... | 67 | rc =3D ppoll(pollfds, nsockets, NULL, NULL); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (2) ...to here |...... | 74 | newpollfds =3D realloc(pollfds, nsockets * sizeof(*pollf= ds)); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~ | | | | | (3) when 'realloc' succeeds, moving buffer | | (4) region created on heap here | 75 | if (!newpollfds) { | | ~ | | | | | (5) following 'false' branch (when 'newpollfds' is non-NULL)... |...... | 78 | pollfds =3D newpollfds; | | ~~~~~~~~~~~~~~~~~~~~ | | | | | (6) ...to here | 79 | pollfds[nsockets - 1].fd =3D accept(pollfds[0].fd, &remo= te, &len); | |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (7) use of uninitialized value '*pollfds.fd' here | On Compiler Explorer: https://godbolt.org/z/EKrnsoaY4 >>From downstream report: https://bugzilla.redhat.com/show_bug.cgi?id=3D2047926#c5=