public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation
@ 2012-05-12 11:01 kilobyte at angband dot pl
2012-05-12 11:03 ` [Bug c++/53330] " kilobyte at angband dot pl
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: kilobyte at angband dot pl @ 2012-05-12 11:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53330
Bug #: 53330
Summary: new() operator can return NULL on a zero-length
allocation
Classification: Unclassified
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: kilobyte@angband.pl
Created attachment 27386
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27386
test case
While in general C++ disallows zero-length arrays, they are explicitly allowed
by the new() operator (C++ 3.7.4.1.2), with a guarantee that such an allocation
will always return an unique non-null pointer.
This worked correctly in 4.6 and before (and clang, and MSVC, ...), 4.7.0
(Debian 4.7.0-8) and trunk@187013 return null if elements of the array have a
constructor and have sizeof() > 0 themselves. For simple types or structs, all
is ok.
Also, if there's a constructor (no regards for sizeof(element)) and the array
length is known at compile time, -Wuninitialized returns incorrect diagnostics
that the returned value is uninitialized.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53330] new() operator can return NULL on a zero-length allocation
2012-05-12 11:01 [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation kilobyte at angband dot pl
@ 2012-05-12 11:03 ` kilobyte at angband dot pl
2013-03-29 13:13 ` kilobyte at angband dot pl
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: kilobyte at angband dot pl @ 2012-05-12 11:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53330
--- Comment #1 from Adam Borowski <kilobyte at angband dot pl> 2012-05-12 11:01:23 UTC ---
Correction: after testing with valgrind, the return value is indeed
uninitialized; the pointer in contructor-but-no-fields case happens to be
non-zero but is junk and will cause a crash when you try to free it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53330] new() operator can return NULL on a zero-length allocation
2012-05-12 11:01 [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation kilobyte at angband dot pl
2012-05-12 11:03 ` [Bug c++/53330] " kilobyte at angband dot pl
@ 2013-03-29 13:13 ` kilobyte at angband dot pl
2013-03-29 13:21 ` kilobyte at angband dot pl
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: kilobyte at angband dot pl @ 2013-03-29 13:13 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53330
--- Comment #2 from Adam Borowski <kilobyte at angband dot pl> 2013-03-29 13:13:21 UTC ---
Created attachment 29750
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29750
updated testcase
Updated testcase: it checks for invalid pointers (by freeing them), and returns
an exit code (if it won't crash first).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53330] new() operator can return NULL on a zero-length allocation
2012-05-12 11:01 [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation kilobyte at angband dot pl
2012-05-12 11:03 ` [Bug c++/53330] " kilobyte at angband dot pl
2013-03-29 13:13 ` kilobyte at angband dot pl
@ 2013-03-29 13:21 ` kilobyte at angband dot pl
2015-08-12 22:38 ` paolo at gcc dot gnu.org
2015-08-12 22:39 ` paolo.carlini at oracle dot com
4 siblings, 0 replies; 6+ messages in thread
From: kilobyte at angband dot pl @ 2013-03-29 13:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53330
--- Comment #3 from Adam Borowski <kilobyte at angband dot pl> 2013-03-29 13:20:53 UTC ---
Re-tested:
* gcc-4.7.2 works on amd64, armhf, x32, fails on i386
* gcc-4.8.0 works on all of the above
(all Debian)
So it appears to be fixed in 4.8, at least on architectures I tried.
Regardless of whether you'll fix it in 4.7 or not, it may be worth adding to
the test suite.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53330] new() operator can return NULL on a zero-length allocation
2012-05-12 11:01 [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation kilobyte at angband dot pl
` (2 preceding siblings ...)
2013-03-29 13:21 ` kilobyte at angband dot pl
@ 2015-08-12 22:38 ` paolo at gcc dot gnu.org
2015-08-12 22:39 ` paolo.carlini at oracle dot com
4 siblings, 0 replies; 6+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-08-12 22:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53330
--- Comment #4 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Wed Aug 12 22:38:04 2015
New Revision: 226840
URL: https://gcc.gnu.org/viewcvs?rev=226840&root=gcc&view=rev
Log:
2015-08-12 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53330
* g++.dg/init/new42.C: New.
Added:
trunk/gcc/testsuite/g++.dg/init/new42.C
Modified:
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53330] new() operator can return NULL on a zero-length allocation
2012-05-12 11:01 [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation kilobyte at angband dot pl
` (3 preceding siblings ...)
2015-08-12 22:38 ` paolo at gcc dot gnu.org
@ 2015-08-12 22:39 ` paolo.carlini at oracle dot com
4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-08-12 22:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53330
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Known to work| |4.9.0, 5.0
Resolution|--- |WORKSFORME
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I'm adding a testcase and closing the bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-08-12 22:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-12 11:01 [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation kilobyte at angband dot pl
2012-05-12 11:03 ` [Bug c++/53330] " kilobyte at angband dot pl
2013-03-29 13:13 ` kilobyte at angband dot pl
2013-03-29 13:21 ` kilobyte at angband dot pl
2015-08-12 22:38 ` paolo at gcc dot gnu.org
2015-08-12 22:39 ` paolo.carlini at oracle dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).