From 8c822182e82bcdb021f00076683ae10a8494cb98 Mon Sep 17 00:00:00 2001 From: shikai-123 Date: Wed, 23 Feb 2022 17:41:21 +0800 Subject: [PATCH] Modify defects of util StrError function is a risk function, and some interface types of decode are modified https://gitee.com/openharmony/js_util_module/issues/I4UZCC Signed-off-by: shikai-123 --- util/js_textdecoder.cpp | 8 ++++---- util/js_textdecoder.h | 6 +++--- util/native_module_util.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index c98f368..55bafc1 100755 --- a/util/js_textdecoder.cpp +++ b/util/js_textdecoder.cpp @@ -73,7 +73,7 @@ namespace OHOS::Util { NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, &data1, &arrayBuffer, &byteOffset)); const char *source = static_cast(data1); UErrorCode codeFlag = U_ZERO_ERROR; - int32_t limit = GetMinByteSize() * length; + size_t limit = GetMinByteSize() * length; size_t len = limit * sizeof(UChar); UChar *arr = nullptr; if (limit > 0) { @@ -146,12 +146,12 @@ namespace OHOS::Util { return result; } - int32_t TextDecoder::GetMinByteSize() const + size_t TextDecoder::GetMinByteSize() const { if (tranTool_ == nullptr) { - return -1; + return 0; } - int32_t res = ucnv_getMinCharSize(tranTool_.get()); + size_t res = ucnv_getMinCharSize(tranTool_.get()); return res; } diff --git a/util/js_textdecoder.h b/util/js_textdecoder.h index 4214469..bc74fda 100755 --- a/util/js_textdecoder.h +++ b/util/js_textdecoder.h @@ -26,7 +26,7 @@ using TransformToolPointer = std::unique_ptr; namespace OHOS::Util { struct DecodeArr { - DecodeArr(UChar *tarPos, size_t tarStaPos, int32_t limLen) + DecodeArr(UChar *tarPos, size_t tarStaPos, size_t limLen) { this->target = tarPos; this->tarStartPos = tarStaPos; @@ -34,7 +34,7 @@ namespace OHOS::Util { } UChar *target = 0; size_t tarStartPos = 0; - int32_t limitLen = 0; + size_t limitLen = 0; }; class TextDecoder { @@ -53,7 +53,7 @@ namespace OHOS::Util { napi_value GetEncoding() const; napi_value GetFatal() const; napi_value GetIgnoreBOM() const; - int32_t GetMinByteSize() const; + size_t GetMinByteSize() const; void Reset() const; UConverter *GetConverterPtr() const { diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index 055abb7..05430b6 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -210,7 +210,7 @@ namespace OHOS::Util { NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, &thisVar, nullptr)); int32_t err = 0; NAPI_CALL(env, napi_get_value_int32(env, argv, &err)); - errInfo = strerror(err); + errInfo = uv_strerror(err); NAPI_CALL(env, napi_create_string_utf8(env, errInfo.c_str(), errInfo.size(), &result)); return result; }