From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6173C3858C98; Mon, 22 Apr 2024 15:57:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6173C3858C98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713801433; bh=nnzILGxyxmfk6j5uLrDR6sb6EEOdiz0COfVzPpFc/Kg=; h=From:To:Subject:Date:From; b=QNX2iaBRW1YIki9GaYTd0bJ/l0kyrp3ANhOyZsjlgs8MRhaA50o8dyE8Yqlz76Z03 3c7A+NukvFbYcZlnVvP6FKO09VPA6AMEt3+FJgkGwvdD7quXJTC781p9dxvYlJZMqG t4O5QygC1v6KLFxsSA3JAmB+xJMz6rSarWbEnWNg= From: "pshevchuk at pshevchuk dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114805] New: placement new doesn't check array length Date: Mon, 22 Apr 2024 15:57:12 +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: unknown 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=3D114805 Bug ID: 114805 Summary: placement new doesn't check array length Product: gcc Version: unknown 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 58007 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D58007&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=