From b2fd81fee470082b416b4796840e3ee6bad18641 Mon Sep 17 00:00:00 2001 From: shikai-123 Date: Wed, 16 Feb 2022 17:44:58 +0800 Subject: [PATCH 1/2] Signed-off-by: shikai-123 Modify defects --- util/js_textdecoder.cpp | 6 +++--- util/js_textdecoder.h | 6 +++--- util/js_textencoder.cpp | 2 +- util/native_module_util.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index 05e574f..c98f368 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; - size_t limit = GetMinByteSize() * length; + int32_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; } - size_t TextDecoder::GetMinByteSize() const + int32_t TextDecoder::GetMinByteSize() const { if (tranTool_ == nullptr) { return -1; } - size_t res = ucnv_getMinCharSize(tranTool_.get()); + int32_t res = ucnv_getMinCharSize(tranTool_.get()); return res; } diff --git a/util/js_textdecoder.h b/util/js_textdecoder.h index bc74fda..4214469 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, size_t limLen) + DecodeArr(UChar *tarPos, size_t tarStaPos, int32_t limLen) { this->target = tarPos; this->tarStartPos = tarStaPos; @@ -34,7 +34,7 @@ namespace OHOS::Util { } UChar *target = 0; size_t tarStartPos = 0; - size_t limitLen = 0; + int32_t limitLen = 0; }; class TextDecoder { @@ -53,7 +53,7 @@ namespace OHOS::Util { napi_value GetEncoding() const; napi_value GetFatal() const; napi_value GetIgnoreBOM() const; - size_t GetMinByteSize() const; + int32_t GetMinByteSize() const; void Reset() const; UConverter *GetConverterPtr() const { diff --git a/util/js_textencoder.cpp b/util/js_textencoder.cpp index 2acd9bd..45bb434 100755 --- a/util/js_textencoder.cpp +++ b/util/js_textencoder.cpp @@ -72,7 +72,7 @@ namespace OHOS::Util { char *writeResult = static_cast(resultData) + byteOffset; int32_t nchars = 0; - int32_t written = 0; + uint32_t written = 0; NativeEngine *engine = reinterpret_cast(env_); NativeValue *nativeValue = reinterpret_cast(src); engine->EncodeToUtf8(nativeValue, writeResult, &written, length, &nchars); diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index d932b28..22ceda4 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -191,8 +191,8 @@ namespace OHOS::Util { size_t argc = 1; napi_value argv = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, &thisVar, nullptr)); - uint32_t err = 0; - NAPI_CALL(env, napi_get_value_uint32(env, argv, &err)); + int32_t err = 0; + NAPI_CALL(env, napi_get_value_int32(env, argv, &err)); errInfo = strerror(err); NAPI_CALL(env, napi_create_string_utf8(env, errInfo.c_str(), errInfo.size(), &result)); return result; -- Gitee From a5cb3b0abdc58566a137dc83e4f4cc16c5ee569a Mon Sep 17 00:00:00 2001 From: shikai-123 Date: Wed, 16 Feb 2022 20:35:06 +0800 Subject: [PATCH 2/2] Modify defects of util Signed-off-by: shikai-123 On branch master Your branch is up to date with 'origin/master'. --- util/js_textencoder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/js_textencoder.cpp b/util/js_textencoder.cpp index 45bb434..d81cdde 100755 --- a/util/js_textencoder.cpp +++ b/util/js_textencoder.cpp @@ -72,7 +72,7 @@ namespace OHOS::Util { char *writeResult = static_cast(resultData) + byteOffset; int32_t nchars = 0; - uint32_t written = 0; + int32_t written = 0; NativeEngine *engine = reinterpret_cast(env_); NativeValue *nativeValue = reinterpret_cast(src); engine->EncodeToUtf8(nativeValue, writeResult, &written, length, &nchars); @@ -81,12 +81,12 @@ namespace OHOS::Util { NAPI_CALL(env_, napi_create_object(env_, &result)); napi_value read = nullptr; - NAPI_CALL(env_, napi_create_uint32(env_, nchars, &read)); + NAPI_CALL(env_, napi_create_int32(env_, nchars, &read)); NAPI_CALL(env_, napi_set_named_property(env_, result, "read", read)); napi_value resWritten = nullptr; - NAPI_CALL(env_, napi_create_uint32(env_, written, &resWritten)); + NAPI_CALL(env_, napi_create_int32(env_, written, &resWritten)); NAPI_CALL(env_, napi_set_named_property(env_, result, "written", resWritten)); -- Gitee