diff --git a/libpandabase/mem/mmap_mem_pool-inl.h b/libpandabase/mem/mmap_mem_pool-inl.h index 3ec9f19095ae1a63932501afc15670a3a7e5084e..eab5e22657b7a94659087c703447f1f2dee8a733 100644 --- a/libpandabase/mem/mmap_mem_pool-inl.h +++ b/libpandabase/mem/mmap_mem_pool-inl.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -377,14 +377,17 @@ inline void MmapMemPool::FreePoolUnsafe(void *mem, size_t size) break; case SpaceType::SPACE_TYPE_COMPILER: compiler_space_current_size_ -= size; + RemoveFromNonObjectPoolsMap(mem); FreeRawMemImpl(mem, size); break; case SpaceType::SPACE_TYPE_INTERNAL: internal_space_current_size_ -= size; + RemoveFromNonObjectPoolsMap(mem); FreeRawMemImpl(mem, size); break; case SpaceType::SPACE_TYPE_CODE: code_space_current_size_ -= size; + RemoveFromNonObjectPoolsMap(mem); FreeRawMemImpl(mem, size); break; default: @@ -395,8 +398,6 @@ inline void MmapMemPool::FreePoolUnsafe(void *mem, size_t size) if (remove_from_pool_map) { pool_map_.RemovePoolFromMap(ToVoidPtr(ToUintPtr(mem) - GetMinObjectAddress()), size); os::mem::ReleasePages(ToUintPtr(mem), ToUintPtr(mem) + size); - } else { - RemoveFromNonObjectPoolsMap(mem); } LOG_MMAP_MEM_POOL(DEBUG) << "Freed " << std::dec << size << " memory for " << SpaceTypeToString(pool_space_type); } diff --git a/static_core/libpandabase/utils/bit_memory_region.h b/static_core/libpandabase/utils/bit_memory_region.h index 38d2ed3b30e7c295f20cc3a34ebed957f7d53e96..3dceffdfda4d1f970cd1d68e45956f64b9256ae7 100644 --- a/static_core/libpandabase/utils/bit_memory_region.h +++ b/static_core/libpandabase/utils/bit_memory_region.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -252,9 +252,9 @@ public: size_t res = 0; size_t i = 0; for (; (i + BITS_PER_UINT32) < length; i += BITS_PER_UINT32) { - res += ark::Popcount(Read(first + i, BITS_PER_UINT32)); + res += static_cast(ark::Popcount(Read(first + i, BITS_PER_UINT32))); } - return res + ark::Popcount(Read(first + i, length - i)); + return res + static_cast(ark::Popcount(Read(first + i, length - i))); } size_t Popcount() const diff --git a/static_core/libpandabase/utils/leb128.h b/static_core/libpandabase/utils/leb128.h index d4d0c75fd825a2aff7b3f74509d34f7d21dbdbf9..97cb4bababd027806391286e2d66a47d77680690 100644 --- a/static_core/libpandabase/utils/leb128.h +++ b/static_core/libpandabase/utils/leb128.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -123,7 +123,7 @@ inline std::tuple DecodeSigned(const uint8_t *data) // NOLINTNEXTLINE(hicpp-signed-bitwise) auto signedExtended = static_cast(static_cast(byte << 1) >> 1); // NOLINTNEXTLINE(hicpp-signed-bitwise) - uint8_t masked = (signedExtended ^ (signedExtended >> PAYLOAD_WIDTH)) | 1; + uint8_t masked = static_cast((signedExtended ^ (signedExtended >> PAYLOAD_WIDTH)) | 1); bool isFull = MinimumBitsToStore(masked) <= shift; if (shift > PAYLOAD_WIDTH) { shift -= PAYLOAD_WIDTH; diff --git a/static_core/libpandafile/bytecode_emitter.cpp b/static_core/libpandafile/bytecode_emitter.cpp index c7ef6fb55ec9fe16f24e9e673b1ff747a4f1ccc8..9ac12306be37e8dcd582cb91c89922597f49aa92 100644 --- a/static_core/libpandafile/bytecode_emitter.cpp +++ b/static_core/libpandafile/bytecode_emitter.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -208,6 +208,8 @@ BytecodeEmitter::ErrorCode BytecodeEmitter::DoReserveSpaceForOffset(const Byteco UNREACHABLE(); // no revcc and no far opcode return ErrorCode::INTERNAL_ERROR; } + ASSERT(insnPc < bytecode_.size()); + ASSERT(insnPc + insnSize <= bytecode_.size()); UpdateBranchOffs(&bytecode_[insnPc], static_cast(insnSize + GetSizeByOpcode(Opcode::JMP_IMM32))); *targetPtr = insnPc + insnSize; Emit(bytecode_.begin() + *targetPtr, Opcode::JMP_IMM32, 0); @@ -254,11 +256,11 @@ int32_t BytecodeEmitter::EstimateMaxDistance(uint32_t insnPc, uint32_t targetPc, std::map::const_iterator it; if (targetPc > insnPc) { it = branches_.lower_bound(insnPc - bias); - distance = static_cast(targetPc - insnPc); + distance = static_cast(targetPc) - static_cast(insnPc); endPc = targetPc - bias; } else if (targetPc < insnPc) { it = branches_.lower_bound(targetPc - bias); - distance = static_cast(targetPc - insnPc); + distance = static_cast(targetPc) - static_cast(insnPc); endPc = insnPc - bias; } else { // Do we support branch to itself? diff --git a/static_core/platforms/unix/libpandabase/cpu_affinity.cpp b/static_core/platforms/unix/libpandabase/cpu_affinity.cpp index cfd8278ee4f4da4c9a046a4b1b9ddbb3ebea9522..a8a41a4afc7e649a8259388c23c83b8ee2c98455 100644 --- a/static_core/platforms/unix/libpandabase/cpu_affinity.cpp +++ b/static_core/platforms/unix/libpandabase/cpu_affinity.cpp @@ -212,7 +212,8 @@ CpuSet::CpuSet() // NOLINT(cppcoreguidelines-pro-type-member-init) void CpuSet::Set(int cpu) { - CPU_SET(cpu, &cpuset_); + ASSERT(cpu >= 0); + CPU_SET(static_cast(cpu), &cpuset_); } void CpuSet::Clear() @@ -222,7 +223,8 @@ void CpuSet::Clear() void CpuSet::Remove(int cpu) { - CPU_CLR(cpu, &cpuset_); + ASSERT(cpu >= 0); + CPU_CLR(static_cast(cpu), &cpuset_); } size_t CpuSet::Count() const @@ -232,7 +234,8 @@ size_t CpuSet::Count() const bool CpuSet::IsSet(int cpu) const { - return CPU_ISSET(cpu, &cpuset_); + ASSERT(cpu >= 0); + return CPU_ISSET(static_cast(cpu), &cpuset_); } bool CpuSet::IsEmpty() const diff --git a/static_core/platforms/unix/libpandabase/exec.h b/static_core/platforms/unix/libpandabase/exec.h index ea30521cac3d1807ef615eb6180bd7a53cb144b9..0d2904352dbe23841a2f2cca3edf73c769339b93 100644 --- a/static_core/platforms/unix/libpandabase/exec.h +++ b/static_core/platforms/unix/libpandabase/exec.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -60,8 +60,8 @@ Expected ExecWithCallback(Callback callback, Span args if (resPid != pid) { return Unexpected(Error(errno)); } - if (WIFEXITED(status)) { // NOLINT(hicpp-signed-bitwise) - return WEXITSTATUS(status); // NOLINT(hicpp-signed-bitwise) + if (WIFEXITED(static_cast(status))) { + return static_cast(WEXITSTATUS(static_cast(status))); } return Unexpected(Error("Process finished improperly")); } diff --git a/static_core/platforms/unix/libpandabase/sighook.cpp b/static_core/platforms/unix/libpandabase/sighook.cpp index 1495083bece3c0b4cb3bc16fbf51b6721609e068..36f05424eb795f80f98f0c465d306df0e030d96a 100644 --- a/static_core/platforms/unix/libpandabase/sighook.cpp +++ b/static_core/platforms/unix/libpandabase/sighook.cpp @@ -276,6 +276,7 @@ void SignalHook::Handler(int signo, siginfo_t *siginfo, void *ucontextRaw) if (handler == SIG_DFL) { // NOLINT LOG(FATAL, RUNTIME) << "Actually signal:" << signo << " | register sigaction's handler == SIG_DFL"; } + ASSERT(handler != nullptr); handler(signo); } diff --git a/static_core/plugins/ets/runtime/ets_exceptions.cpp b/static_core/plugins/ets/runtime/ets_exceptions.cpp index 1e8271cc4d94f41b8dcc9012b0a305d5a0696944..5ffef9bfd33fd3ecb86c188108500abca737d516 100644 --- a/static_core/plugins/ets/runtime/ets_exceptions.cpp +++ b/static_core/plugins/ets/runtime/ets_exceptions.cpp @@ -51,6 +51,10 @@ static EtsObject *CreateExceptionInstance(EtsCoroutine *coro, EtsClass *cls, Ets return nullptr; } + if (UNLIKELY(msg.GetPtr() == nullptr)) { + return nullptr; + } + Method::Proto proto(Method::Proto::ShortyVector {panda_file::Type(panda_file::Type::TypeId::VOID), panda_file::Type(panda_file::Type::TypeId::REFERENCE), panda_file::Type(panda_file::Type::TypeId::REFERENCE)}, @@ -86,6 +90,10 @@ static EtsObject *CreateErrorInstance(EtsCoroutine *coro, EtsClass *cls, EtsHand return nullptr; } + if (UNLIKELY(msg.GetPtr() == nullptr)) { + return nullptr; + } + Method::Proto proto(Method::Proto::ShortyVector {panda_file::Type(panda_file::Type::TypeId::VOID), panda_file::Type(panda_file::Type::TypeId::REFERENCE), panda_file::Type(panda_file::Type::TypeId::REFERENCE)}, diff --git a/static_core/plugins/ets/runtime/interop_js/call/arg_convertors.h b/static_core/plugins/ets/runtime/interop_js/call/arg_convertors.h index 1109a8c153cf55ff1b73fcb9cf5cf18a9dad32c3..f9054ce9e0b7760e99bec61b54206e544b4fbc11 100644 --- a/static_core/plugins/ets/runtime/interop_js/call/arg_convertors.h +++ b/static_core/plugins/ets/runtime/interop_js/call/arg_convertors.h @@ -51,8 +51,9 @@ template return true; } if (IsNull(env, jsVal)) { - if (LIKELY(klass->IsAssignableFrom(ctx->GetNullValueClass()))) { - storeRes(ctx->GetNullValue()->GetCoreType()); + auto nullVal = ctx->GetNullValue(); + if (LIKELY(nullVal != nullptr) && klass->IsAssignableFrom(ctx->GetNullValueClass())) { + storeRes(nullVal->GetCoreType()); return true; } } @@ -255,6 +256,10 @@ template *resSlot = GetUndefined(env); return true; } + if (UNLIKELY(ctx == nullptr || ctx->GetNullValue() == nullptr)) { + *resSlot = GetUndefined(env); + return true; + } if (UNLIKELY(ref == ctx->GetNullValue()->GetCoreType())) { *resSlot = GetNull(env); return true; diff --git a/static_core/plugins/ets/runtime/interop_js/jsbacktrace/backtrace.cpp b/static_core/plugins/ets/runtime/interop_js/jsbacktrace/backtrace.cpp index e48962a71aee1a2920331afa1e524ac48cf69ae9..247b9bc65b69896fac5c0af7675a6f6decfc1c79 100755 --- a/static_core/plugins/ets/runtime/interop_js/jsbacktrace/backtrace.cpp +++ b/static_core/plugins/ets/runtime/interop_js/jsbacktrace/backtrace.cpp @@ -89,7 +89,7 @@ int Backtrace::EtsSymbolize(uintptr_t pc, uintptr_t mapBase, uint32_t bcOffset, if (size < 0) { LOG(ERROR, RUNTIME) << "copy funtionname failed!"; } - function->line = panda_file::debug_helpers::GetLineNumber(mda, bcOffset, file.get()); + function->line = static_cast(panda_file::debug_helpers::GetLineNumber(mda, bcOffset, file.get())); function->column = 0; function->codeBegin = methodInfos[mid].codeBegin; function->codeSize = methodInfos[mid].codeSize; diff --git a/static_core/plugins/ets/runtime/types/ets_arraybuffer.h b/static_core/plugins/ets/runtime/types/ets_arraybuffer.h index 0e1fa750b3f56153d33be091d67f6a3befecba44..d9cd5e836bb026da27e2bee70c6b2da14e58cef0 100644 --- a/static_core/plugins/ets/runtime/types/ets_arraybuffer.h +++ b/static_core/plugins/ets/runtime/types/ets_arraybuffer.h @@ -304,7 +304,8 @@ private: void InitializeByDefault(EtsCoroutine *coro, size_t length) { ObjectAccessor::SetObject(coro, this, GetManagedDataOffset(), AllocateNonMovableArray(length)); - byteLength_ = length; + ASSERT(length <= static_cast(std::numeric_limits::max())); + byteLength_ = static_cast(length); nativeData_ = GetAddress(EtsByteArray::FromCoreType(ObjectAccessor::GetObject(coro, this, GetManagedDataOffset()))); ASSERT(nativeData_ != 0); @@ -316,7 +317,8 @@ private: void *data, EtsFinalize finalizerFunction, void *finalizerHint, size_t length) { ObjectAccessor::SetObject(coro, this, GetManagedDataOffset(), nullptr); - byteLength_ = length; + ASSERT(length <= static_cast(std::numeric_limits::max())); + byteLength_ = static_cast(length); nativeData_ = reinterpret_cast(data); ASSERT(nativeData_ != 0); isResizable_ = ToEtsBoolean(false); diff --git a/static_core/plugins/ets/runtime/types/ets_job.cpp b/static_core/plugins/ets/runtime/types/ets_job.cpp index b6076021767120414a69c5678dc3460bf87e300c..c876b79c7651dceeb06e227fe710ceddee5d2c56 100644 --- a/static_core/plugins/ets/runtime/types/ets_job.cpp +++ b/static_core/plugins/ets/runtime/types/ets_job.cpp @@ -25,7 +25,13 @@ EtsJob *EtsJob::Create(EtsCoroutine *coro) { [[maybe_unused]] EtsHandleScope scope(coro); auto *klass = PlatformTypes(coro)->coreJob; - auto hJob = EtsHandle(coro, EtsJob::FromEtsObject(EtsObject::Create(coro, klass))); + auto hJobObject = EtsObject::Create(coro, klass); + if (hJobObject == nullptr) { + LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(panda_file::SourceLang::ETS); + ThrowNullPointerException(ctx, coro); + return nullptr; + } + auto hJob = EtsHandle(coro, EtsJob::FromEtsObject(hJobObject)); ASSERT(hJob.GetPtr() != nullptr); auto *mutex = EtsMutex::Create(coro); hJob->SetMutex(coro, mutex);