From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 77368385BF81; Tue, 28 Apr 2020 11:56:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77368385BF81 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588074989; bh=WqQOQ8HNJPM/LmjcVqfPTQrOQViKV6cTAmechvHvloo=; h=From:To:Subject:Date:From; b=OwfItSaJ/EY9VP2VdOfZYmhSVYdaKw8BiVsUf1eXro8u2pOFeDm00bgMTC+eVKC4m Tw1q7spf7IpbK8uG1+pbSynvgK+0jxSuCrpLRbKgqzdiBJ5Yh/Pl3xsAD0HBm2oObB tauHlTCDInBiVmENax6fEydaqsjjDLfKTTMK3rXw= From: "vincent.riviere at freesbee dot fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/94815] New: Abusive -Wrestrict warning with sprintf Date: Tue, 28 Apr 2020 11:56:29 +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: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent.riviere at freesbee dot fr 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 cf_gcctarget 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, 28 Apr 2020 11:56:29 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94815 Bug ID: 94815 Summary: Abusive -Wrestrict warning with sprintf Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: vincent.riviere at freesbee dot fr Target Milestone: --- Target: m68k-elf Testcase: $ cat foo.c && m68k-elf-gcc -c foo.c -Wall -O char *strcpy(char *, const char *); int sprintf(char *, const char *, ...); char* myalloc(int n); void f(void) { char* buf =3D myalloc(20); char* str1 =3D buf; char* str2 =3D buf + 10; strcpy(str2, "123"); sprintf(str1, "ABC%s", str2); } foo.c: In function 'f': foo.c:13:5: warning: 'sprintf' argument 3 may overlap destination object 'b= uf' [-Wrestrict] 13 | sprintf(str1, "ABC%s", str2); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ This warning is a unexpected because: 1) strcpy() and sprintf() are declared without __restrict, but __restrict r= ules are still actually used. 2) In this simple example, it is obvious that the buffer will not overflow. This is annoying, because it prevents creating several logical buffers from= a single allocation.=