commit | 47de5a0591b38a91e991cd45c0cb71bb185ef908 | [log] [tgz] |
---|---|---|
author | Nicolas Pitre <npitre@baylibre.com> | Mon Jan 25 21:13:02 2021 -0500 |
committer | Anas Nashif <anas.nashif@intel.com> | Tue Feb 02 19:08:24 2021 -0500 |
tree | 6e6b91ab95440e0a18bc090466764b30f45bc746 | |
parent | 593997046bfffeb45699d4a1aecb4b7f223fee4f [diff] |
libc/minimal: fix realloc() failure case It is said that the C17 realloc() behavior is to return the original pointer on error and that's what is implemented here. This may be confused with a successful realloc() and nobody else does that. Instead, a failed realloc() should return NULL, leave the original memory intact and set errno to ENOMEM. This is the behavior described by all the following references: Linux/glibc: https://man7.org/linux/man-pages/man3/malloc.3.html NetBSD https://man.netbsd.org/realloc.3 Microsoft https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/realloc Mac OS X https://developer.apple.com/library/archive/documentation/System/\ Conceptual/ManPages_iPhoneOS/man3/reallocf.3.html Open Group Base Specifications Issue 6 https://pubs.opengroup.org/onlinepubs/009604599/functions/realloc.html PTC MKS Toolkit https://www.mkssoftware.com/docs/man3/realloc.3.asp Let's get in line with the most common behavior. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>