unix,win: handle zero-sized allocations uniformly

`malloc(0)` and `realloc(p, 0)` can either return NULL or a unique
pointer. Make our custom allocator return NULL for consistency across
platforms and libcs.

PR-URL: https://github.com/libuv/libuv/pull/2038
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
Ben Noordhuis 2018-10-17 00:14:50 +02:00
parent 6e23a36603
commit ba7802315d

View File

@ -72,7 +72,9 @@ char* uv__strndup(const char* s, size_t n) {
}
void* uv__malloc(size_t size) {
if (size > 0)
return uv__allocator.local_malloc(size);
return NULL;
}
void uv__free(void* ptr) {
@ -91,7 +93,10 @@ void* uv__calloc(size_t count, size_t size) {
}
void* uv__realloc(void* ptr, size_t size) {
if (size > 0)
return uv__allocator.local_realloc(ptr, size);
uv__free(ptr);
return NULL;
}
int uv_replace_allocator(uv_malloc_func malloc_func,