diff options
author | Ujjwal Sharma <usharma1998@gmail.com> | 2018-08-29 16:39:55 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-09-02 15:25:16 +0300 |
commit | a55c57b8c48d4d09d3fb74ffddab6e87d10f2030 (patch) | |
tree | abfb494acec7b5bdc1e817a2f9de4a3cb9c11de7 /src/stream_base.cc | |
parent | 67403b3a849f86ccd03bcf3b829a89d74471f9ca (diff) |
src: rework (mostly internal) functions to use Maybes
Rework all affected functions to use Maybes, thus improving error
handling substantially in internal functions, API functions as well as
utilities.
Co-authored-by: Michaƫl Zasso <targos@protonmail.com>
PR-URL: https://github.com/nodejs/node/pull/21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/stream_base.cc')
-rw-r--r-- | src/stream_base.cc | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/stream_base.cc b/src/stream_base.cc index bb46ea1febb..f429f3593fd 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -108,11 +108,12 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) { enum encoding encoding = ParseEncoding(env->isolate(), chunks->Get(i * 2 + 1)); size_t chunk_size; - if (encoding == UTF8 && string->Length() > 65535) - chunk_size = StringBytes::Size(env->isolate(), string, encoding); - else - chunk_size = StringBytes::StorageSize(env->isolate(), string, encoding); - + if (encoding == UTF8 && string->Length() > 65535 && + !StringBytes::Size(env->isolate(), string, encoding).To(&chunk_size)) + return 0; + else if (!StringBytes::StorageSize(env->isolate(), string, encoding) + .To(&chunk_size)) + return 0; storage_size += chunk_size; } @@ -214,10 +215,12 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) { // For UTF8 strings that are very long, go ahead and take the hit for // computing their actual size, rather than tripling the storage. size_t storage_size; - if (enc == UTF8 && string->Length() > 65535) - storage_size = StringBytes::Size(env->isolate(), string, enc); - else - storage_size = StringBytes::StorageSize(env->isolate(), string, enc); + if (enc == UTF8 && string->Length() > 65535 && + !StringBytes::Size(env->isolate(), string, enc).To(&storage_size)) + return 0; + else if (!StringBytes::StorageSize(env->isolate(), string, enc) + .To(&storage_size)) + return 0; if (storage_size > INT_MAX) return UV_ENOBUFS; |