diff options
author | Anna Henningsen <anna@addaleax.net> | 2016-09-10 16:43:08 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2016-09-29 09:46:42 +0200 |
commit | eb927fac38a50252e11ebe0da1764e85294f95f0 (patch) | |
tree | 2c498902818f71c21f62361497ee608f7aa79be2 /src/string_bytes.cc | |
parent | 506cda6ea69e185bd27b1caec1d91c6b9041584c (diff) | |
download | android-node-v8-eb927fac38a50252e11ebe0da1764e85294f95f0.tar.gz android-node-v8-eb927fac38a50252e11ebe0da1764e85294f95f0.tar.bz2 android-node-v8-eb927fac38a50252e11ebe0da1764e85294f95f0.zip |
src: add Malloc() size param + overflow detection
Adds an optional second parameter to `node::Malloc()` and
an optional third parameter to `node::Realloc()` giving the
size/number of items to be allocated, in the style of `calloc(3)`.
Use a proper overflow check using division;
the previous `CHECK_GE(n * size, n);` would not detect all cases
of overflow (e.g. `size == SIZE_MAX / 2 && n == 3`).
PR-URL: https://github.com/nodejs/node/pull/8482
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r-- | src/string_bytes.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc index fa641af746..fddf61de63 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*>(node::Malloc(length * sizeof(*new_data))); + static_cast<TypeName*>(node::Malloc(length, sizeof(*new_data))); if (new_data == nullptr) { return Local<String>(); } |