From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4F6113858418; Sun, 14 Nov 2021 14:57:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F6113858418 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103233] Warning from system libraries in user code: CWE-476 -Werror=analyzer-null-dereference Date: Sun, 14 Nov 2021 14:57:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: WAITING 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_status cf_reconfirmed_on everconfirmed 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: Sun, 14 Nov 2021 14:57:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103233 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |WAITING Last reconfirmed| |2021-11-14 Ever confirmed|0 |1 --- Comment #2 from Jonathan Wakely --- (In reply to Alejandro Colomar from comment #0) > There are two problems here: >=20 > One is a dereference of a NULL pointer in the standard C++ library code > (at least that's what -fanalyzer reports). The analyzer doesn't support C++ properly yet, and is completely wrong here. See below. > Another is that I'm seeing the error while compiling user code (my librar= y): > What error? Please provide the code to reproduce the problem, not just a UR= L, see https://gcc.gnu.org/bugs > |/usr/include/c++/11/bits/stl_vector.h:346:25: > | 346 | return __n !=3D 0 ? _Tr::allocate(_M_impl, __n) : > pointer(); > | |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 > ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > | | | > | | (7) following 'false' branch... This cannot happen. The length is this->size() + 1 and we already checked f= or overflow, so it is guaranteed to be a positive integer. > |...... > | 127 | return static_cast<_Tp*>(::operator new(__n * > sizeof(_Tp))); > | |=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 > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > | | | > | | (12) > ...to here > | | (13) t= his > call could return NULL This is nonsense, operator new(size_t) cannot return null.=