From a00ccb0fb9eb716925058b0a20fcec9251de3309 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Thu, 1 Sep 2016 18:14:02 -0400 Subject: src: normalize malloc, realloc malloc(0) and realloc(ptr, 0) have implementation-defined behavior in that the standard allows them to either return a unique pointer or a nullptr for zero-sized allocation requests. Normalize by always using a nullptr. - Introduce node::malloc, node::realloc and node::calloc that should be used throught our source. - Update all existing node source files to use the new functions instead of the native allocation functions. Fixes: https://github.com/nodejs/node/issues/7549 PR-URL: https://github.com/nodejs/node/pull/7564 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen --- src/string_bytes.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/string_bytes.cc') diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 668a3b1efe..fa641af746 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -54,7 +54,7 @@ class ExternString: public ResourceType { return scope.Escape(String::Empty(isolate)); TypeName* new_data = - static_cast(malloc(length * sizeof(*new_data))); + static_cast(node::Malloc(length * sizeof(*new_data))); if (new_data == nullptr) { return Local(); } @@ -624,7 +624,7 @@ Local StringBytes::Encode(Isolate* isolate, case ASCII: if (contains_non_ascii(buf, buflen)) { - char* out = static_cast(malloc(buflen)); + char* out = static_cast(node::Malloc(buflen)); if (out == nullptr) { return Local(); } @@ -659,7 +659,7 @@ Local StringBytes::Encode(Isolate* isolate, case BASE64: { size_t dlen = base64_encoded_size(buflen); - char* dst = static_cast(malloc(dlen)); + char* dst = static_cast(node::Malloc(dlen)); if (dst == nullptr) { return Local(); } @@ -678,7 +678,7 @@ Local StringBytes::Encode(Isolate* isolate, case HEX: { size_t dlen = buflen * 2; - char* dst = static_cast(malloc(dlen)); + char* dst = static_cast(node::Malloc(dlen)); if (dst == nullptr) { return Local(); } -- cgit v1.2.3