!1314 JSAPI告警修复

Merge pull request !1314 from 张鸿雨/master
This commit is contained in:
openharmony_ci 2024-08-24 08:39:05 +00:00 committed by Gitee
commit 356e2638bb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 14 additions and 4 deletions

View File

@ -35,7 +35,7 @@ void Blob::Init(uint8_t *blob, unsigned int length)
void Blob::Init(Blob *blob, int start)
{
if (blob != nullptr) {
if (blob != nullptr && blob->raw_ != nullptr) {
this->raw_ = reinterpret_cast<uint8_t *>(malloc(blob->length_));
if (raw_ == nullptr) {
HILOG_FATAL("Blob constructor malloc failed");
@ -56,7 +56,7 @@ void Blob::Init(Blob *blob, int start, int end)
if ((start > 0 && end < 0) || (start < 0 && end > 0)) {
return;
}
if (blob == nullptr) {
if (blob == nullptr || blob->raw_ == nullptr) {
return;
}
unsigned int length = static_cast<unsigned int>(end - start);
@ -103,7 +103,7 @@ unsigned int Blob::GetLength()
void Blob::ReadBytes(uint8_t *data, int length)
{
if (memcpy_s(data, length, raw_, length) != EOK) {
if (raw_ != nullptr && memcpy_s(data, length, raw_, length) != EOK) {
HILOG_FATAL("read bytes from blob error");
}
}

View File

@ -861,8 +861,16 @@ static napi_value Compare(napi_env env, napi_callback_info info)
NAPI_CALL(env, napi_get_value_uint32(env, args[3], &length));
Buffer *targetBuf = nullptr;
NAPI_CALL(env, napi_unwrap(env, args[0], reinterpret_cast<void **>(&targetBuf)));
if (targetBuf == nullptr) {
HILOG_FATAL("buffer:: targetBuf is NULL");
return nullptr;
}
Buffer *sBuf = nullptr;
NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast<void **>(&sBuf)));
if (sBuf == nullptr) {
HILOG_FATAL("buffer:: sBuf is NULL");
return nullptr;
}
int res = sBuf->Compare(targetBuf, targetStart, sourceStart, length);
napi_value result = nullptr;
napi_create_int32(env, res, &result);

View File

@ -120,6 +120,7 @@ HWTEST_F(NativeEngineTest, ConvertXmlTest001, testing::ext::TestSize.Level0)
convertXml->DealNapiStrValue(env, encodingVal, encodingStr);
EXPECT_STREQ(verisonStr.c_str(), "1.0");
EXPECT_STREQ(encodingStr.c_str(), "utf-8");
delete convertXml;
}
/* @tc.name: ConvertXmlTest002

View File

@ -203,6 +203,7 @@ std::string Console::GetTimerOrCounterName(napi_env env, napi_callback_info info
argv[0] = buffer;
}
std::string name = Helper::NapiHelper::GetPrintString(env, argv[0]);
delete[] argv;
if (name.empty()) {
Helper::ErrorHelper::ThrowError(env, Helper::ErrorHelper::TYPE_ERROR,
"Timer or Counter name must be not null.");

View File

@ -1204,7 +1204,7 @@ class RationalNumber {
public constructor(num: number, den: number);
public constructor(num?: number, den?: number) {
if (!num && !den) {
return;
}
else {
num = den < 0 ? num * (-1) : num;