diff options
author | Michael Dawson <michael_dawson@ca.ibm.com> | 2016-09-01 18:14:02 -0400 |
---|---|---|
committer | Michael Dawson <michael_dawson@ca.ibm.com> | 2016-09-06 09:39:06 -0400 |
commit | a00ccb0fb9eb716925058b0a20fcec9251de3309 (patch) | |
tree | 91c1aa556e0519d73c4b04238a5cf02f67342886 /src/string_bytes.cc | |
parent | a290ddfdc9cd9453886d433060c5132095d916c4 (diff) | |
download | android-node-v8-a00ccb0fb9eb716925058b0a20fcec9251de3309.tar.gz android-node-v8-a00ccb0fb9eb716925058b0a20fcec9251de3309.tar.bz2 android-node-v8-a00ccb0fb9eb716925058b0a20fcec9251de3309.zip |
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 <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r-- | src/string_bytes.cc | 8 |
1 files changed, 4 insertions, 4 deletions
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<TypeName*>(malloc(length * sizeof(*new_data))); + static_cast<TypeName*>(node::Malloc(length * sizeof(*new_data))); if (new_data == nullptr) { return Local<String>(); } @@ -624,7 +624,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate, case ASCII: if (contains_non_ascii(buf, buflen)) { - char* out = static_cast<char*>(malloc(buflen)); + char* out = static_cast<char*>(node::Malloc(buflen)); if (out == nullptr) { return Local<String>(); } @@ -659,7 +659,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate, case BASE64: { size_t dlen = base64_encoded_size(buflen); - char* dst = static_cast<char*>(malloc(dlen)); + char* dst = static_cast<char*>(node::Malloc(dlen)); if (dst == nullptr) { return Local<String>(); } @@ -678,7 +678,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate, case HEX: { size_t dlen = buflen * 2; - char* dst = static_cast<char*>(malloc(dlen)); + char* dst = static_cast<char*>(node::Malloc(dlen)); if (dst == nullptr) { return Local<String>(); } |