mirror of
https://gitee.com/openharmony/commonlibrary_ets_utils
synced 2024-11-27 09:30:48 +00:00
commit
356e2638bb
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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.");
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user