From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7B875385780F; Wed, 15 Sep 2021 15:21:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B875385780F From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/102337] bogus -Wformat-truncation due to incomplete sprintf/strlen integration Date: Wed, 15 Sep 2021 15:21:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW 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: blocked short_desc Message-ID: In-Reply-To: References: 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: Wed, 15 Sep 2021 15:21:55 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102337 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |85741 Summary|possibly wrong warning |bogus -Wformat-truncation |about truncation |due to incomplete | |sprintf/strlen integration --- Comment #1 from Martin Sebor --- In the absence of data flow information -Wformat-truncation (and -Wformat-overflow) uses the sizes of the arrays pointed to by arguments to = the %s directive as the upper bound of the lengths of the strings being formatt= ed.=20 In the test case in comment #0 the results of the first two snprintf calls computed by GCC are discarded (not used for subsequent data flow analysis) = and so the warning assumes that the length of each of the two strings in the la= st call to snprintf() is 127 and triggers. To do better the warning needs to = be enhanced to feed the results of snprintf calls to the strlen pass so that t= hey are available when computing the lengths of strings in subsequent calls. T= his enhancement is the subject of pr92813 so this bug is effectively a duplicat= e of that one. (Replacing the first two snprintf calls with strcpy avoids the warning beca= use string lengths computed by GCC for arguments of strcpy calls are available = to the snprintf warning.) Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D85741 [Bug 85741] [meta-bug] bogus/missing -Wformat-overflow=