From 7df2cabc93e9d88c806bf6a2ebed59f1b481c5b4 Mon Sep 17 00:00:00 2001 From: oh_ci Date: Mon, 9 Sep 2024 02:51:50 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!1666=20?= =?UTF-8?q?:=209.2=20fix=20warning'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OAT.xml | 67 ------------------- frameworks/cj/src/relational_store_utils.cpp | 10 +-- frameworks/js/napi/common/src/js_utils.cpp | 8 ++- .../src/napi_data_ability_predicates.cpp | 3 - .../js/napi/rdb/src/napi_rdb_predicates.cpp | 24 ------- .../native/appdatafwk/src/shared_block.cpp | 18 ----- frameworks/native/rdb/include/sqlite_utils.h | 1 - frameworks/native/rdb/src/sqlite_utils.cpp | 22 +----- interfaces/inner_api/rdb/BUILD.gn | 1 - rdbmock/frameworks/native/rdb/stdlib.cpp | 32 --------- rdbmock/frameworks/native/rdb/stdlib.h | 30 --------- 11 files changed, 11 insertions(+), 205 deletions(-) delete mode 100644 OAT.xml delete mode 100644 rdbmock/frameworks/native/rdb/stdlib.cpp delete mode 100644 rdbmock/frameworks/native/rdb/stdlib.h diff --git a/OAT.xml b/OAT.xml deleted file mode 100644 index b2439302b..000000000 --- a/OAT.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - LICENSE - - - - - - - - \ No newline at end of file diff --git a/frameworks/cj/src/relational_store_utils.cpp b/frameworks/cj/src/relational_store_utils.cpp index e31dbf5b9..a6e2795de 100644 --- a/frameworks/cj/src/relational_store_utils.cpp +++ b/frameworks/cj/src/relational_store_utils.cpp @@ -222,7 +222,7 @@ namespace Relational { for (size_t i = 0; i < devices.size(); i++) { cArrStr.head[i] = MallocCString(devices[i]); } - cArrStr.size = static_cast(devices.size()); + cArrStr.size = devices.size(); return cArrStr; } @@ -281,7 +281,7 @@ namespace Relational { ModifyTime MapToModifyTime(std::map &map, int32_t &errCode) { ModifyTime modifyTime{0}; - modifyTime.size = static_cast(map.size()); + modifyTime.size = map.size(); modifyTime.key = static_cast(malloc(sizeof(RetPRIKeyType) * modifyTime.size)); modifyTime.value = static_cast(malloc(sizeof(uint64_t) * modifyTime.size)); if (modifyTime.key == nullptr || modifyTime.value == nullptr) { @@ -293,7 +293,7 @@ namespace Relational { int64_t index = 0; for (auto it = map.begin(); it != map.end(); ++it) { modifyTime.key[index] = VariantToRetPRIKeyType(it->first); - modifyTime.value[index] = static_cast((it->second).date); + modifyTime.value[index] = (it->second).date; index++; } return modifyTime; @@ -312,7 +312,7 @@ namespace Relational { for (size_t i = 0; i < arr.size(); i++) { types.head[i] = VariantToRetPRIKeyType(arr[i]); } - types.size = static_cast(arr.size()); + types.size = arr.size(); return types; } @@ -348,7 +348,7 @@ namespace Relational { infos.head[index] = ToRetChangeInfo(origin, it); index++; } - infos.size = static_cast(changeInfo.size()); + infos.size = changeInfo.size(); return infos; } diff --git a/frameworks/js/napi/common/src/js_utils.cpp b/frameworks/js/napi/common/src/js_utils.cpp index c909b1229..02e054b67 100644 --- a/frameworks/js/napi/common/src/js_utils.cpp +++ b/frameworks/js/napi/common/src/js_utils.cpp @@ -242,17 +242,19 @@ int32_t JSUtils::Convert2Value(napi_env env, napi_value jsValue, std::string &ou if (buffSize >= JSUtils::MAX_VALUE_LENGTH - 1) { buffSize = JSUtils::MAX_VALUE_LENGTH - 1; } - std::unique_ptr buffer = std::make_unique(buffSize + 1); + char *buffer = (char *)malloc((buffSize + 1) * sizeof(char)); if (buffer == nullptr) { LOG_ERROR("buffer data is nullptr."); return napi_invalid_arg; } - status = napi_get_value_string_utf8(env, jsValue, buffer.get(), buffSize + 1, &buffSize); + status = napi_get_value_string_utf8(env, jsValue, buffer, buffSize + 1, &buffSize); if (status != napi_ok) { LOG_ERROR("napi_get_value_string_utf8 failed, status = %{public}d", status); + free(buffer); return status; } - output = std::string(buffer.get()); + output = std::string(buffer); + free(buffer); return status; } diff --git a/frameworks/js/napi/dataability/src/napi_data_ability_predicates.cpp b/frameworks/js/napi/dataability/src/napi_data_ability_predicates.cpp index 93d528a01..ccebc3192 100644 --- a/frameworks/js/napi/dataability/src/napi_data_ability_predicates.cpp +++ b/frameworks/js/napi/dataability/src/napi_data_ability_predicates.cpp @@ -180,9 +180,6 @@ std::shared_ptr DataAbilityPredicatesProxy::Ge napi_value thiz = nullptr; napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } return predicatesProxy->predicates_; } diff --git a/frameworks/js/napi/rdb/src/napi_rdb_predicates.cpp b/frameworks/js/napi/rdb/src/napi_rdb_predicates.cpp index 609e8cc94..2cea75290 100644 --- a/frameworks/js/napi/rdb/src/napi_rdb_predicates.cpp +++ b/frameworks/js/napi/rdb/src/napi_rdb_predicates.cpp @@ -206,9 +206,6 @@ std::shared_ptr RdbPredicatesProxy::GetNativePredicate napi_value thiz = nullptr; napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr); napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } return predicatesProxy->predicates_; } @@ -220,9 +217,6 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldArrayByName(napi_env env, napi napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); RdbPredicatesProxy *predicatesProxy = nullptr; napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } int version = predicatesProxy->apiversion; RDB_NAPI_ASSERT_FROMV9(env, argc == 1, std::make_shared("1"), version); @@ -247,9 +241,6 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldByName( napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); RdbPredicatesProxy *predicatesProxy = nullptr; napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } int version = predicatesProxy->apiversion; RDB_NAPI_ASSERT_FROMV9(env, argc == 1, std::make_shared("1"), version); @@ -267,9 +258,6 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseInt32FieldByName( napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); RdbPredicatesProxy *predicatesProxy = nullptr; napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } int version = predicatesProxy->apiversion; RDB_NAPI_ASSERT_FROMV9(env, argc == 1, std::make_shared("1"), version); @@ -287,9 +275,6 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldAndValueArray(napi_env env, na napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); RdbPredicatesProxy *predicatesProxy = nullptr; napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } int version = predicatesProxy->apiversion; // Ensure that argc contains 2 parameters RDB_NAPI_ASSERT_FROMV9(env, argc == 2, std::make_shared("2"), version); @@ -314,9 +299,6 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldAndValue(napi_env env, napi_ca napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); RdbPredicatesProxy *predicatesProxy = nullptr; napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } int version = predicatesProxy->apiversion; // 2 represents the number of parameters RDB_NAPI_ASSERT_FROMV9(env, argc == 2, std::make_shared("2"), version); @@ -342,9 +324,6 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldAndStringValue(napi_env env, n napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); RdbPredicatesProxy *predicatesProxy = nullptr; napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } int version = predicatesProxy->apiversion; // 2 represents the number of parameters RDB_NAPI_ASSERT_FROMV9(env, argc == 2, std::make_shared("2"), version); @@ -366,9 +345,6 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldLowAndHigh( napi_get_cb_info(env, info, &argc, args, &thiz, nullptr); RdbPredicatesProxy *predicatesProxy = nullptr; napi_unwrap(env, thiz, reinterpret_cast(&predicatesProxy)); - if (predicatesProxy == nullptr) { - return nullptr; - } int version = predicatesProxy->apiversion; // 3 represents the number of parameters RDB_NAPI_ASSERT_FROMV9(env, argc == 3, std::make_shared("3"), version); diff --git a/frameworks/native/appdatafwk/src/shared_block.cpp b/frameworks/native/appdatafwk/src/shared_block.cpp index 707d6b758..69067bdb0 100644 --- a/frameworks/native/appdatafwk/src/shared_block.cpp +++ b/frameworks/native/appdatafwk/src/shared_block.cpp @@ -249,9 +249,6 @@ uint32_t *SharedBlock::AllocRowOffset() uint32_t rowPos = mHeader->rowNums % ROW_NUM_IN_A_GROUP; RowGroupHeader *group = static_cast(OffsetToPtr(mHeader->groupOffset[groupPos])); - if (group == nullptr) { - return nullptr; - } mHeader->rowNums += 1; return group->rowOffsets + rowPos; } @@ -267,9 +264,6 @@ SharedBlock::CellUnit *SharedBlock::GetCellUnit(uint32_t row, uint32_t column) uint32_t groupPos = row / ROW_NUM_IN_A_GROUP; uint32_t rowPos = row % ROW_NUM_IN_A_GROUP; - if (groupPos > GROUP_NUM) { - return nullptr; - } RowGroupHeader *group = reinterpret_cast(mData + mHeader->groupOffset[groupPos]); return reinterpret_cast(mData + group->rowOffsets[rowPos]) + column; } @@ -314,9 +308,6 @@ int SharedBlock::PutBlobOrString(uint32_t row, uint32_t column, const void *valu } uint32_t groupPos = row / ROW_NUM_IN_A_GROUP; uint32_t rowPos = row % ROW_NUM_IN_A_GROUP; - if (groupPos > GROUP_NUM) { - return SHARED_BLOCK_NO_MEMORY; - } RowGroupHeader *group = reinterpret_cast(mData + mHeader->groupOffset[groupPos]); CellUnit *cellUnit = reinterpret_cast(mData + group->rowOffsets[rowPos]) + column; uint32_t offset = mHeader->unusedOffset; @@ -350,9 +341,6 @@ int SharedBlock::PutLong(uint32_t row, uint32_t column, int64_t value) uint32_t groupPos = row / ROW_NUM_IN_A_GROUP; uint32_t rowPos = row % ROW_NUM_IN_A_GROUP; - if (groupPos > GROUP_NUM) { - return SHARED_BLOCK_NO_MEMORY; - } RowGroupHeader *group = reinterpret_cast(mData + mHeader->groupOffset[groupPos]); CellUnit *cellUnit = reinterpret_cast(mData + group->rowOffsets[rowPos]) + column; cellUnit->type = CELL_UNIT_TYPE_INTEGER; @@ -371,9 +359,6 @@ int SharedBlock::PutDouble(uint32_t row, uint32_t column, double value) uint32_t groupPos = row / ROW_NUM_IN_A_GROUP; uint32_t rowPos = row % ROW_NUM_IN_A_GROUP; - if (groupPos > GROUP_NUM) { - return SHARED_BLOCK_NO_MEMORY; - } RowGroupHeader *group = reinterpret_cast(mData + mHeader->groupOffset[groupPos]); CellUnit *cellUnit = reinterpret_cast(mData + group->rowOffsets[rowPos]) + column; cellUnit->type = CELL_UNIT_TYPE_FLOAT; @@ -392,9 +377,6 @@ int SharedBlock::PutNull(uint32_t row, uint32_t column) uint32_t groupPos = row / ROW_NUM_IN_A_GROUP; uint32_t rowPos = row % ROW_NUM_IN_A_GROUP; - if (groupPos > GROUP_NUM) { - return SHARED_BLOCK_NO_MEMORY; - } RowGroupHeader *group = reinterpret_cast(mData + mHeader->groupOffset[groupPos]); CellUnit *cellUnit = reinterpret_cast(mData + group->rowOffsets[rowPos]) + column; diff --git a/frameworks/native/rdb/include/sqlite_utils.h b/frameworks/native/rdb/include/sqlite_utils.h index 22e240380..22b2fbc61 100644 --- a/frameworks/native/rdb/include/sqlite_utils.h +++ b/frameworks/native/rdb/include/sqlite_utils.h @@ -60,7 +60,6 @@ public: static std::string GetSlavePath(const std::string& name); static bool TryAccessSlaveLock(const std::string &dbPath, bool isDelete, bool needCreate, bool isSlaveFailure = false); - static std::string RealPath(const std::string &inOriPath); private: struct SqlType { diff --git a/frameworks/native/rdb/src/sqlite_utils.cpp b/frameworks/native/rdb/src/sqlite_utils.cpp index 43593f4e6..547004c61 100644 --- a/frameworks/native/rdb/src/sqlite_utils.cpp +++ b/frameworks/native/rdb/src/sqlite_utils.cpp @@ -193,12 +193,7 @@ bool SqliteUtils::IsSlaveDbName(const std::string &fileName) bool SqliteUtils::TryAccessSlaveLock(const std::string &dbPath, bool isDelete, bool needCreate, bool isSlaveFailure) { - auto realPath = RealPath(dbPath); - if (realPath.empty()) { - LOG_ERROR("get real path file failed, len = %{public}zu.", realPath.size()); - return false; - } - std::string lockFile = isSlaveFailure ? realPath + "-slaveFailure" : realPath + "-syncInterrupt"; + std::string lockFile = isSlaveFailure ? dbPath + "-slaveFailure" : dbPath + "-syncInterrupt"; if (isDelete) { if (std::remove(lockFile.c_str()) != 0) { LOG_WARN("remove slave lock failed errno %{public}d %{public}s", errno, Anonymous(lockFile).c_str()); @@ -236,20 +231,5 @@ std::string SqliteUtils::GetSlavePath(const std::string& name) } return name.substr(0, pos) + slaveSuffix; } - -std::string SqliteUtils::RealPath(const std::string &inOriPath) -{ - std::vector realPath(PATH_MAX + 1, '\0'); - if (inOriPath.size() > PATH_MAX || realpath(inOriPath.c_str(), realPath.data()) == nullptr) { - LOG_ERROR("get real path fail!"); - return ""; - } - auto outOriPath = std::string(realPath.data()); - if (access(outOriPath.c_str(), F_OK) != 0) { - LOG_ERROR("FileDeal : access errInfo=%{public}s", strerror(errno)); - return ""; - } - return outOriPath; -} } // namespace NativeRdb } // namespace OHOS diff --git a/interfaces/inner_api/rdb/BUILD.gn b/interfaces/inner_api/rdb/BUILD.gn index dbd58227c..63e0aad49 100644 --- a/interfaces/inner_api/rdb/BUILD.gn +++ b/interfaces/inner_api/rdb/BUILD.gn @@ -332,7 +332,6 @@ if (is_ohos && !build_ohos_sdk) { deps = base_deps sources += [ - "${relational_store_mock_path}/frameworks/native/rdb/stdlib.cpp", "${relational_store_native_path}/rdb/mock/src/rdb_radar_reporter.cpp", "${relational_store_native_path}/rdb/mock/src/task_executor.cpp", ] diff --git a/rdbmock/frameworks/native/rdb/stdlib.cpp b/rdbmock/frameworks/native/rdb/stdlib.cpp deleted file mode 100644 index 556e0df4e..000000000 --- a/rdbmock/frameworks/native/rdb/stdlib.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2024 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "stdlib.h" -#define IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16)) -#define IOC_READ 2U -#define IOR(a, b, c) IOC(IOC_READ, (a), (b), sizeof(c)) -namespace OHOS { -namespace NativeRdb { -#ifdef __cplusplus -extern "C" { -#endif -static char *realpath(const char *__restrict path, char *__restrict resolved_path) -{ - return nullptr; -} -#ifdef __cplusplus -} -#endif -} // namespace NativeRdb -} // namespace OHOS \ No newline at end of file diff --git a/rdbmock/frameworks/native/rdb/stdlib.h b/rdbmock/frameworks/native/rdb/stdlib.h deleted file mode 100644 index 4c999ded7..000000000 --- a/rdbmock/frameworks/native/rdb/stdlib.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2024 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MOCK_STDLIB_H -#define MOCK_STDLIB_H -namespace OHOS { -namespace NativeRdb { -#ifdef __cplusplus -extern "C" { -#endif -static char *realpath(const char *__restrict path, char *__restrict resolved_path); - -#ifdef __cplusplus -} -#endif -} // namespace NativeRdb -} // namespace OHOS -#endif //MOCK_STDLIB_H \ No newline at end of file