mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
src: provide allocation + nullptr check shortcuts
Provide shortcut `node::CheckedMalloc()` and friends that replace `node::Malloc()` + `CHECK_NE(·, nullptr);` combinations in a few places. Backport-PR-URL: https://github.com/nodejs/node/pull/16587 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>
This commit is contained in:
1 parent
4aec8cfcd2
commit
6a0eb9f6cf
13 files changed
+69
-51
No files matched your search
+4
-4
@@ -53,7 +53,7 @@ class ExternString: public ResourceType {
|
||||
if (length == 0)
|
||||
return scope.Escape(String::Empty(isolate));
|
||||
|
||||
TypeName* new_data = node::Malloc<TypeName>(length);
|
||||
TypeName* new_data = node::UncheckedMalloc<TypeName>(length);
|
||||
if (new_data == nullptr) {
|
||||
return Local<String>();
|
||||
}
|
||||
@@ -609,7 +609,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
|
||||
|
||||
case ASCII:
|
||||
if (contains_non_ascii(buf, buflen)) {
|
||||
char* out = node::Malloc(buflen);
|
||||
char* out = node::UncheckedMalloc(buflen);
|
||||
if (out == nullptr) {
|
||||
return Local<String>();
|
||||
}
|
||||
@@ -644,7 +644,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
|
||||
|
||||
case BASE64: {
|
||||
size_t dlen = base64_encoded_size(buflen);
|
||||
char* dst = node::Malloc(dlen);
|
||||
char* dst = node::UncheckedMalloc(dlen);
|
||||
if (dst == nullptr) {
|
||||
return Local<String>();
|
||||
}
|
||||
@@ -663,7 +663,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
|
||||
|
||||
case HEX: {
|
||||
size_t dlen = buflen * 2;
|
||||
char* dst = node::Malloc(dlen);
|
||||
char* dst = node::UncheckedMalloc(dlen);
|
||||
if (dst == nullptr) {
|
||||
return Local<String>();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user