RFR(xs): 8168542: os::realloc should return a valid pointer for input size=0

Alan Burlison Alan.Burlison at oracle.com
Tue Oct 25 08:40:52 UTC 2016


On 24/10/2016 14:12, Thomas Stüfe wrote:

> In short, this fixes a corner case for os::realloc() which currently
> returns NULL if input size is zero.

For reference, here's what POSIX.1-2008 says:

malloc:

"If the space cannot be allocated, a null pointer shall be returned. If 
the size of the space requested is 0, the behavior is 
implementation-defined: either a null pointer shall be returned, or the 
behavior shall be as if the size were some non-zero value, except that 
the behavior is undefined if the returned pointer is used to access an 
object."

realloc:

"If the size of the space requested is zero, the behavior shall be 
implementation-defined: either a null pointer is returned, or the 
behavior shall be as if the size were some non-zero value, except that 
the behavior is undefined if the returned pointer is used to access an 
object. If the space cannot be allocated, the object shall remain 
unchanged."

C11 says basically the same thing.

-- 
Alan Burlison
--


More information about the hotspot-runtime-dev mailing list