diff --git a/interfaces/kits/js/src/mod_fileio/common_func.cpp b/interfaces/kits/js/src/mod_fileio/common_func.cpp index 0ec589448f73c3e84751c8de6ffd7f8d5f4068bf..7e192446a46ceb123ba3367d9be4268086411d63 100644 --- a/interfaces/kits/js/src/mod_fileio/common_func.cpp +++ b/interfaces/kits/js/src/mod_fileio/common_func.cpp @@ -132,7 +132,7 @@ static tuple GetActualLenV9(napi_env env, int64_t bufLen, int64_t return { true, retLen }; } -int CommonFunc::ConvertJsFlags(int &flags) +unsigned int CommonFunc::ConvertJsFlags(unsigned int &flags) { static constexpr unsigned int usrReadOnly = 00; static constexpr unsigned int usrWriteOnly = 01; diff --git a/interfaces/kits/js/src/mod_fileio/common_func.h b/interfaces/kits/js/src/mod_fileio/common_func.h index 2ef467d28fadee3a4f40bd48e4010528801d7a9d..5ee78586d0e1a34b94195c9657e17095d1b958f0 100644 --- a/interfaces/kits/js/src/mod_fileio/common_func.h +++ b/interfaces/kits/js/src/mod_fileio/common_func.h @@ -36,7 +36,7 @@ constexpr int SYNC = 04010000; void InitOpenMode(napi_env env, napi_value exports); struct CommonFunc { - static int ConvertJsFlags(int &flags); + static unsigned int ConvertJsFlags(unsigned int &flags); static std::tuple GetReadArg(napi_env env, napi_value readBuf, napi_value option); diff --git a/interfaces/kits/js/src/mod_fileio/properties/create_randomaccessfile.cpp b/interfaces/kits/js/src/mod_fileio/properties/create_randomaccessfile.cpp index 461390164b9121092e7756196e01c898d0b0ea8e..81f03027985c4b19335214b4f5fd296713ad5a1c 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/create_randomaccessfile.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/create_randomaccessfile.cpp @@ -85,17 +85,17 @@ static tuple ParseJsFileAndFP(napi_env env, napi_value p return { false, FileInfo { false, {}, {} }, -1 }; }; -static tuple GetJsFlags(napi_env env, const NFuncArg &funcArg, FileInfo &fileInfo) +static tuple GetJsFlags(napi_env env, const NFuncArg &funcArg, FileInfo &fileInfo) { - int flags = O_RDONLY; - bool succ = false; + unsigned int flags = O_RDONLY; if (fileInfo.isPath) { if (funcArg.GetArgc() >= NARG_CNT::THREE && !NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_function)) { - tie(succ, flags) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32(); - if (!succ) { + auto [succ, authFlags] = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32(); + if (!succ || authFlags < 0) { UniError(EINVAL).ThrowErr(env, "Invalid flags"); return { false, flags }; } + flags = static_cast(authFlags); (void)CommonFunc::ConvertJsFlags(flags); } } diff --git a/interfaces/kits/js/src/mod_fileio/properties/open_v9.cpp b/interfaces/kits/js/src/mod_fileio/properties/open_v9.cpp index 0ccb51d7571e87bd41ae9fe0366026e7a9db7714..acde01e4bcf5a33b2032f552e8d1f36e7626fa52 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/open_v9.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/open_v9.cpp @@ -39,16 +39,16 @@ namespace DistributedFS { namespace ModuleFileIO { using namespace std; -static tuple GetJsFlags(napi_env env, const NFuncArg &funcArg) +static tuple GetJsFlags(napi_env env, const NFuncArg &funcArg) { - int mode = O_RDONLY; - bool succ = false; + unsigned int mode = O_RDONLY; if (funcArg.GetArgc() >= NARG_CNT::TWO && NVal(env, funcArg[NARG_POS::SECOND]).TypeIs(napi_number)) { - tie(succ, mode) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); + auto [succ, authMode] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); if (!succ) { UniError(EINVAL, true).ThrowErr(env); return { false, mode }; } + mode = static_cast(authMode); (void)CommonFunc::ConvertJsFlags(mode); } return { true, mode }; diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index f01e35b0b2d32b1d60ec7559173d44d127b6933f..b3f81c2ddeffe929b78d938cc4d6c175b304bfcf 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -43,15 +43,15 @@ using namespace OHOS::AppExecFwk; static tuple GetJsFlags(napi_env env, const NFuncArg &funcArg) { unsigned int mode = O_RDONLY; - bool succ = false; if (funcArg.GetArgc() >= NARG_CNT::TWO && NVal(env, funcArg[NARG_POS::SECOND]).TypeIs(napi_number)) { - tie(succ, mode) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); + auto [succ, authMode] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); unsigned int invalidMode = (O_WRONLY | O_RDWR); - if (!succ || ((mode & invalidMode) == invalidMode)) { + if (!succ || authMode < 0 || ((authMode & invalidMode) == invalidMode)) { HILOGE("Invalid mode"); NError(EINVAL).ThrowErr(env); return { false, mode }; } + mode = static_cast(authMode); (void)CommonFunc::ConvertJsFlags(mode); } return { true, mode };