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 <shikai25@huawei.com>
This commit is contained in:
shikai-123
2022-02-23 17:41:21 +08:00
parent 55ba66d2de
commit 8c822182e8
3 changed files with 8 additions and 8 deletions
+4 -4
View File
@@ -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<char*>(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;
}
+3 -3
View File
@@ -26,7 +26,7 @@
using TransformToolPointer = std::unique_ptr<UConverter, void(*)(UConverter*)>;
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
{
+1 -1
View File
@@ -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;
}