From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3AFD4384DD00; Mon, 22 Apr 2024 15:58:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AFD4384DD00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713801524; bh=meQC0kv9wU3sRALZ3lFB16cXQs27ZAw8qCC7WkHjWNE=; h=From:To:Subject:Date:From; b=dVPkgdIeSSv8z7ejfXhsvBKYRS9EVkUvW97wSfYiMEoRDOfw3uWcGOGk9LGRflHpS SGqZuYzaLSsF0s8kWeLcxnhqrN88iq6OZqxcFrp2Ecsn9t/JqO8YXsjTv2sGvCv6np 1/UA+krJscSvdu9m5R4/X+hQkqAu19pVLbpYx9m8= From: "pshevchuk at pshevchuk dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114806] New: placement new doesn't check array length Date: Mon, 22 Apr 2024 15:58:43 +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: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pshevchuk at pshevchuk dot com 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 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114806 Bug ID: 114806 Summary: placement new doesn't check array length Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pshevchuk at pshevchuk dot com Target Milestone: --- Created attachment 58008 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D58008&action=3Dedit Example code but as attachment #include #include int main() { int sz =3D -1; char buf[9]; char* res =3D new (buf) char[sz]; std::puts(res =3D=3D (char*) nullptr? "correct" : "wrong"); } This program should output "correct", since: expr.new.9: array bound is erroneous since it's less than zero before conversion to std::size_t (9.1) expr.new.9.5.1: the placement new is nothrow, so the result of this operati= on must be nullptr. It isn't Curiously, if you replace the allocated type with an array of ints, it will incorrectly throw the std::bad_array_new_length exception instead of return= ing nullptr. Seems to be present in gcc 8.2 and in gcc13 too=