Modifying Code Alarms

Signed-off-by: hwx1163501 <hanjing35@huawei.com>
issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I83M46
This commit is contained in:
hwx1163501 2023-09-25 13:03:34 +08:00
parent 95e4a84a2e
commit 0cfe428522
18 changed files with 57 additions and 56 deletions

View File

@ -107,7 +107,6 @@ JSTaggedValue NumberHelper::DoubleToString(JSThread *thread, double number, int
auto value = bit_cast<uint64_t>(number);
value += 1;
double delta = HALF * (bit_cast<double>(value) - number);
if (fraction != 0 && fraction >= delta) {
buffer[fractionCursor++] = '.';
while (fraction >= delta) {
@ -159,8 +158,10 @@ JSTaggedValue NumberHelper::DoubleToString(JSThread *thread, double number, int
size_t size = fractionCursor - integerCursor;
std::unique_ptr<char[]> result = std::make_unique<char[]>(size);
memcpy_s(result.get(), size, buffer + integerCursor, size);
if (memcpy_s(result.get(), size, buffer + integerCursor, size) != EOK) {
LOG_FULL(FATAL) << "memcpy_s failed";
UNREACHABLE();
}
return BuiltinsBase::GetTaggedString(thread, result.get());
}

View File

@ -2767,7 +2767,8 @@ void Builtins::LazyInitializeSharedArrayBuffer(const JSHandle<GlobalEnv> &env) c
[[maybe_unused]] EcmaHandleScope scope(thread_);
JSHandle<JSObject> globalObject(thread_, env->GetGlobalObject());
JSHandle<JSTaggedValue> key(factory_->NewFromUtf8("SharedArrayBuffer"));
auto accessor = factory_->NewInternalAccessor(nullptr, reinterpret_cast<void *>(BuiltinsLazyCallback::SharedArrayBuffer));
auto accessor =
factory_->NewInternalAccessor(nullptr, reinterpret_cast<void *>(BuiltinsLazyCallback::SharedArrayBuffer));
SetLazyAccessor(globalObject, key, accessor);
env->SetSharedArrayBufferFunction(thread_, accessor);
}

View File

@ -1531,7 +1531,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle
if (!global && !sticky) {
lastIndex = 0;
}
uint32_t lastIndexInput = lastIndex;
uint32_t lastIndexInput = static_cast<uint32_t>(lastIndex);
if (useCache) {
JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, pattern, flags, inputStr,
RegExpExecResultCache::EXEC_TYPE, regexp,

View File

@ -382,7 +382,7 @@ void ElfBuilder::FixSymtab(llvm::ELF::Elf64_Shdr* shdr)
uint32_t secSize = des_[FullSecIndex].GetSecSize(ElfSecName::SYMTAB);
uint64_t secAddr = des_[FullSecIndex].GetSecAddr(ElfSecName::SYMTAB);
uint32_t secNum = GetSecNum();
uint32_t secNum = static_cast<uint32_t>(GetSecNum());
uint64_t textSecOffset = sectionToShdr_[ElfSecName::TEXT].sh_offset;
uint32_t shStrTabIndex = GetShIndex(ElfSecName::SHSTRTAB);
uint32_t textSecIndex = GetShIndex(ElfSecName::TEXT);
@ -393,7 +393,7 @@ void ElfBuilder::FixSymtab(llvm::ELF::Elf64_Shdr* shdr)
for (size_t i = 0; i < n; ++i) {
Elf64_Sym* sy = &syms[i];
if (sy->getBinding() != llvm::ELF::STB_LOCAL && localCount == -1) {
localCount = i;
localCount = static_cast<int>(i);
}
if (sy->getType() == llvm::ELF::STT_SECTION) {
sy->st_shndx = shStrTabIndex;
@ -405,7 +405,7 @@ void ElfBuilder::FixSymtab(llvm::ELF::Elf64_Shdr* shdr)
sy->st_shndx = 0;
}
}
shdr->sh_info = localCount;
shdr->sh_info = static_cast<uint32_t>(localCount);
}
/*
@ -452,7 +452,7 @@ void ElfBuilder::PackELFSections(std::ofstream &file)
llvm::ELF::Elf64_Off curSecOffset = ComputeEndAddrOfShdr(secNum);
file.seekp(curSecOffset);
int i = GetShIndex(ElfSecName::TEXT);
int i = static_cast<int>(GetShIndex(ElfSecName::TEXT));
auto shStrTab = FindShStrTab();
for (auto const &[secName, secInfo] : sections) {

View File

@ -689,7 +689,7 @@ void ArrayBoundsCheckElimination::ProcessIndexCheck(GateRegion *loopHeader, Gate
void ArrayBoundsCheckElimination::ProcessIf(IntegerStack &pushed, GateRegion *parent, OpCode cond)
{
auto& gateLists = parent->GetGates();
for (int i = gateLists.size() - 1; i >= 0; i--) { // Found the last BinaryOp
for (int i = static_cast<int>(gateLists.size()) - 1; i >= 0; i--) { // Found the last BinaryOp
GateRef gate = gateLists[i];
if (gate == Circuit::NullGate()) continue;
OpCode opGate = acc_.GetOpCode(gate);

View File

@ -416,10 +416,7 @@ public:
// key:constantpool index, value:ItemData
using Item = std::unordered_map<uint64_t, ItemData>;
ConstantPoolInfo(JSPandaFile* jsPandaFile) :
items_(ItemType::ITEM_TYPE_NUM, Item{}),
jsPandaFile_(jsPandaFile)
{}
ConstantPoolInfo(JSPandaFile* jsPandaFile) : items_(ItemType::ITEM_TYPE_NUM, Item{}), jsPandaFile_(jsPandaFile) {}
Item& GetCPItem(ItemType type)
{

View File

@ -534,7 +534,7 @@ ElementsKind GateAccessor::TryGetElementsKind(GateRef gate) const
OpCode op = GetOpCode(gate);
if (op == OpCode::JS_BYTECODE) {
auto elementKind = gatePtr->GetJSBytecodeMetaData()->GetElementsKind();
if (static_cast<uint32_t>(elementKind) == 4) {
if (static_cast<uint32_t>(elementKind) == 4) { // 4:elementKind
return ElementsKind::NUMBER;
}
return gatePtr->GetJSBytecodeMetaData()->GetElementsKind();

View File

@ -140,7 +140,7 @@ void name##StubBuilder::GenerateCircuitImpl(GateRef glue, GateRef sp, GateRef pc
Jump(&dispatch); \
} \
Bind(&initialized); \
callback.TryDump(); \
(callback).TryDump(); \
Jump(&dispatch); \
} \
Bind(&dispatch);

View File

@ -105,9 +105,10 @@ public:
static constexpr int32_t UINT30_MAX = 0x3fffffff;
static constexpr int32_t TYPED_ARRAY_ONHEAP_MAX = JSTypedArray::MAX_ONHEAP_LENGTH;
static constexpr int32_t UINT18_MAX = (1 << 18) - 1;
static const inline std::vector<int32_t> rangeBounds_ = { INT32_MIN, INT32_MIN + 1, -UINT18_MAX, -TYPED_ARRAY_ONHEAP_MAX,
-1, 0, 1, TYPED_ARRAY_ONHEAP_MAX - 1, TYPED_ARRAY_ONHEAP_MAX, TYPED_ARRAY_ONHEAP_MAX + 1,
TYPED_ARRAY_ONHEAP_MAX * 3, UINT18_MAX, UINT30_MAX, UINT30_MAX + 1, INT32_MAX - 1, INT32_MAX };
static const inline std::vector<int32_t> rangeBounds_ = {INT32_MIN, INT32_MIN + 1,
-UINT18_MAX, -TYPED_ARRAY_ONHEAP_MAX, -1, 0, 1, TYPED_ARRAY_ONHEAP_MAX - 1,
TYPED_ARRAY_ONHEAP_MAX, TYPED_ARRAY_ONHEAP_MAX + 1, TYPED_ARRAY_ONHEAP_MAX * 3,
UINT18_MAX, UINT30_MAX, UINT30_MAX + 1, INT32_MAX - 1, INT32_MAX };
static RangeInfo NONE()
{
@ -187,20 +188,22 @@ public:
int32_t GetMaxMulResult(const RangeInfo &rhs) const
{
return std::max({ TryMul(min_, rhs.min_), TryMul(min_, rhs.max_), TryMul(max_, rhs.min_), TryMul(max_, rhs.max_) });
return std::max({ TryMul(min_, rhs.min_), TryMul(min_, rhs.max_),
TryMul(max_, rhs.min_), TryMul(max_, rhs.max_) });
}
int32_t GetMinMulResult(const RangeInfo &rhs) const
{
return std::min({ TryMul(min_, rhs.min_), TryMul(min_, rhs.max_), TryMul(max_, rhs.min_), TryMul(max_, rhs.max_) });
return std::min({ TryMul(min_, rhs.min_), TryMul(min_, rhs.max_),
TryMul(max_, rhs.min_), TryMul(max_, rhs.max_) });
}
int32_t TryMul(int32_t lhs, int32_t rhs) const
{
if (MaybeMulOverflow(lhs, rhs)){
if (MaybeMulOverflow(lhs, rhs)) {
return INT32_MAX;
}
if (MaybeMulUnderflow(lhs, rhs)){
if (MaybeMulUnderflow(lhs, rhs)) {
return INT32_MIN;
}
return lhs * rhs;

View File

@ -383,7 +383,7 @@ void NumberSpeculativeLowering::VisitNumberMod(GateRef gate)
}
GateRef result = Circuit::NullGate();
if (gateType.IsIntType()) {
if(GetRange(right).MaybeZero()) {
if (GetRange(right).MaybeZero()) {
builder_.Int32CheckRightIsZero(right);
}
result = CalculateInts<Op>(left, right);
@ -628,7 +628,7 @@ GateRef NumberSpeculativeLowering::CalculateInts(GateRef left, GateRef right)
break;
}
case TypedBinOp::TYPED_MUL:
if(!leftRange.MaybeMulOverflowOrUnderflow(rightRange)) {
if (!leftRange.MaybeMulOverflowOrUnderflow(rightRange)) {
return builder_.Int32Mul(left, right);
}
res = builder_.MulWithOverflow(left, right);

View File

@ -779,11 +779,11 @@ GateRef NumberSpeculativeRetype::TryConvertConstant(GateRef gate, bool needInt32
if (acc_.GetGateType(gate).IsNJSValueType()) {
MachineType mType = acc_.GetMachineType(gate);
if(mType == MachineType::I32) {
if (mType == MachineType::I32) {
int32_t rawValue = acc_.GetInt32FromConstant(gate);
double value = static_cast<double>(rawValue);
return needInt32 ? builder_.Int32(rawValue) : builder_.Double(value);
} else if(mType == MachineType::F64 && !needInt32) {
} else if (mType == MachineType::F64 && !needInt32) {
double rawValue = acc_.GetFloat64FromConstant(gate);
return builder_.Double(rawValue);
} else {
@ -792,11 +792,11 @@ GateRef NumberSpeculativeRetype::TryConvertConstant(GateRef gate, bool needInt32
}
JSTaggedValue value(acc_.GetConstantValue(gate));
if(value.IsInt()) {
if (value.IsInt()) {
int32_t rawValue = value.GetInt();
double doubleValue = static_cast<double>(rawValue);
return needInt32 ? builder_.Int32(rawValue) : builder_.Double(doubleValue);
} else if(value.IsDouble() && !needInt32) {
} else if (value.IsDouble() && !needInt32) {
double rawValue = value.GetDouble();
return builder_.Double(rawValue);
}

View File

@ -119,7 +119,7 @@ public:
abcName_ = value;
} else if (strcmp(key, KEY_ABC_OFFSET) == 0) {
char *str = nullptr;
abcOffset_ = strtol(value, &str, 0);
abcOffset_ = static_cast<uint32_t>(strtol(value, &str, 0));
} else if (strcmp(key, KEY_ABC_SIZE) == 0) {
char *str = nullptr;
abcSize_ = static_cast<uint32_t>(strtol(value, &str, 0));

View File

@ -294,7 +294,7 @@ JSHandle<JSHClass> TSHClassGenerator::CreateCHClass(const JSThread *thread,
JSHandle<TSObjectType> constructorType(thread, classType->GetConstructorType());
JSHandle<TSObjLayoutInfo> tsLayout(thread, constructorType->GetObjLayoutInfo());
uint32_t numOfProps = tsLayout->GetNumOfProperties() + ClassInfoExtractor::STATIC_RESERVED_LENGTH;
JSHandle<JSHClass> hclass;
JSHandle<JSHClass> hclass;
if (LIKELY(numOfProps <= PropertyAttributes::MAX_FAST_PROPS_CAPACITY)) {
TSManager *tsManager = thread->GetCurrentEcmaContext()->GetTSManager();
const GlobalEnvConstants *globalConst = thread->GlobalConstants();

View File

@ -83,7 +83,7 @@ public:
int ShouldFreeMore(size_t cachedSize) {
os::memory::LockHolder lock(lock_);
int result = regularMapCommitted_.size();
size_t result = regularMapCommitted_.size();
return result - cachedSize / REGULAR_MMAP_SIZE;
}

View File

@ -555,8 +555,7 @@ void LocalSpace::Stop()
uintptr_t NonMovableSpace::CheckAndAllocate(size_t size)
{
if (maximumCapacity_ == committedSize_ && GetHeapObjectSize() > MAX_NONMOVABLE_LIVE_OBJ_SIZE &&
!heap_->GetOldGCRequested())
{
!heap_->GetOldGCRequested()) {
heap_->CollectGarbage(TriggerGCType::OLD_GC, GCReason::ALLOCATION_LIMIT);
}
return Allocate(size);

View File

@ -511,7 +511,7 @@ JSHandle<JSTaggedValue> ModuleManager::ResolveModuleWithMerge(
JSRecordInfo recordInfo;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(recordName, recordInfo);
if (!hasRecord) {
CString msg = "cannot find record '" + recordName + "', please check the request path.'"
CString msg = "cannot find record '" + recordName + "', please check the request path.'"
+ moduleFileName + "'.";
LOG_FULL(ERROR) << msg;
THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str());

View File

@ -116,7 +116,7 @@ void ArkStackMapParser::GetMethodOffsetInfo(uintptr_t callSiteAddr, std::map<uin
ASSERT(it->kind == LocationTy::Kind::CONSTANT);
ASSERT(std::holds_alternative<LLVMStackMapType::IntType>(it->value));
auto v = std::get<LLVMStackMapType::IntType>(it->value);
info[static_cast<int32_t>(SpecVregIndex::FIRST_METHOD_OFFSET_INDEX) - id] = v;
info[static_cast<int32_t>(SpecVregIndex::FIRST_METHOD_OFFSET_INDEX) - id] = static_cast<uint32_t>(v);
}
}

View File

@ -21,27 +21,27 @@ import cv2
import tempfile
import pytest
webPath = os.path.realpath("../dist")
web_path = os.path.realpath("../dist")
class MyHttpRequestHandler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=webPath, **kwargs)
super().__init__(*args, directory=web_path, **kwargs)
httpd = socketserver.TCPServer(("", 9999), MyHttpRequestHandler)
driver = webdriver.Chrome()
actions = ActionChains(driver)
reader = easyocr.Reader(['ch_sim', 'en'], verbose=False)
windowWidth = -1
windowHeight = -1
tempImageFile = os.path.join(tempfile.gettempdir(), "test.png")
window_width = -1
window_height = -1
temp_image_file = os.path.join(tempfile.gettempdir(), "test.png")
def cut_image(image, x, y, w, h):
x = int(x)
y = int(y)
return image[y:y+h, x:x+w]
return image[y:y + h, x:x + w]
oldx = 0
@ -50,7 +50,7 @@ oldy = 0
def click_on_page(x, y):
global oldx, oldy
actions.move_by_offset(x-oldx, y-oldy).click().perform()
actions.move_by_offset(x - oldx, y - oldy).click().perform()
oldx = x
oldy = y
time.sleep(1)
@ -71,9 +71,9 @@ def setup():
print("setup : selenium打开测试页面")
driver.implicitly_wait(10)
driver.get("http://127.0.0.1:9999")
global windowWidth, windowHeight
windowWidth = driver.execute_script("return document.body.clientWidth")
windowHeight = driver.execute_script("return document.body.clientHeight")
global window_width, window_height
window_width = driver.execute_script("return document.body.clientWidth")
window_height = driver.execute_script("return document.body.clientHeight")
def teardown():
@ -85,16 +85,16 @@ def teardown():
def test_loading(): # 验证载入中画面
driver.get_screenshot_as_file(tempImageFile)
image = cv2.imread(tempImageFile)
result = reader.readtext(cut_image(image, windowWidth/2-100, windowHeight/2-20, 200, 40))
driver.get_screenshot_as_file(temp_image_file)
image = cv2.imread(temp_image_file)
result = reader.readtext(cut_image(image, window_width / 2 - 100, window_height / 2 - 20, 200, 40))
assert result[0][1][:7] == "Loading"
def test_start(): # 验证主画面显示
time.sleep(5)
driver.get_screenshot_as_file(tempImageFile)
image = cv2.imread(tempImageFile)
driver.get_screenshot_as_file(temp_image_file)
image = cv2.imread(temp_image_file)
result = reader.readtext(cut_image(image, 10, 100, 60, 20))
assert result[0][1] == "隐藏选中"
@ -107,7 +107,7 @@ def find_string_in_result(s, result):
if d < dis:
dis = d
p = i
if dis < len(s)/2:
if dis < len(s) / 2:
return result[p]
return False
@ -116,8 +116,8 @@ def test_selectfunc(): # 点击优化类型切换下拉菜单,选择优化类
click_on_page(420, 50)
click_on_page(420, 150)
driver.get_screenshot_as_file(tempImageFile)
image = cv2.imread(tempImageFile)
driver.get_screenshot_as_file(temp_image_file)
image = cv2.imread(temp_image_file)
result = reader.readtext(image)
ret = find_string_in_result("0,CIRCUIT_ROOT", result)
assert ret != False
@ -127,8 +127,8 @@ def test_hide(): # 点击state和root按钮隐藏0,CIRCUIT_ROOT
click_on_page(40, 80)
click_on_page(350, 80)
driver.get_screenshot_as_file(tempImageFile)
image = cv2.imread(tempImageFile)
driver.get_screenshot_as_file(temp_image_file)
image = cv2.imread(temp_image_file)
result = reader.readtext(image)
ret = find_string_in_result("0,CIRCUIT_ROOT", result)
assert ret == False