From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 39FF7383E815; Sun, 10 May 2020 23:09:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39FF7383E815 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589152165; bh=rBaBNZzGtpVMG/f/0bR01F30IxqTWls3gpUO4zXxq0M=; h=From:To:Subject:Date:From; b=GSFsd4j7jK57FFHv3maSI+b3l7N9XStIbwW9B53SXeBQWMzuH63eiomWofXeFCjGF NBDWs/axU8FXLrfyLwGLHHhoR6CmEzIk3Actxmz1wti/Y/BXVathdO7a53wlNScQZf 6EJmm9gBbrTCCNRup62oWimC5PXxrB8avvbCdco8= From: "noloader at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/95043] New: GCC 10 Analyzer and false positive on 'memcpy(dest, src, count);' Date: Sun, 10 May 2020 23:09: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: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: noloader at gmail dot com 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: Sun, 10 May 2020 23:09:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95043 Bug ID: 95043 Summary: GCC 10 Analyzer and false positive on 'memcpy(dest, src, count);' Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: noloader at gmail dot com Target Milestone: --- Created attachment 48500 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48500&action=3Dedit Preprocessed source file idea.ii Hi Everyone, I'm trying out the analyzer on a C++ project. I'm working on Fedora 32 with= GCC 10. $ gcc --version gcc (GCC) 10.0.1 20200430 (Red Hat 10.0.1-0.14) Here's what I am seeing: | 527 | if (src && dest) | | ~~ | | | | | (9) ...to here | | (10) following =E2=80=98true=E2=80=99 branch... | 528 | memcpy(dest, src, count); | | ~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | | | (12) argument 1 (=E2=80=98dest=E2=80=99) NULL where no= n-null expected Here's the source file: https://github.com/weidai11/cryptopp/blob/master/misc.h#L506. And the funct= ion (with extra noise omitted): inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count) { if (count > sizeInBytes) throw InvalidArgument("memcpy_s: buffer overflow"); if (src && dest) memcpy(dest, src, count); } I have not been able to reproduce this with a reproducer. The reproducer sh= own below fails to tickle the issue. Attached is the preprocessed source file with the problem, idea.ii.tar.gz. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The reproducer shown below fails to reproduce the issue. $ cat test.cxx #include #include #include #include inline void my_memcpy(void* dest, size_t sizeInBytes, const void* src, size_t count) { if (count > sizeInBytes) throw std::runtime_error("Overflow"); if(dest && src) memcpy(dest, src, count); } int main(int argc, char* argv[]) { char buf[16]; my_memcpy(NULL, 16, argv[0], strlen(argv[0])); return 0; }=