diff --git a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp index c7db1223aef54b23b679a6ae6491cdfabca543a4..c7a423489b86db89d3f2ba1be4958ffa49026ecb 100644 --- a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp @@ -244,7 +244,7 @@ bool Rmdirs(const string &path) string ConvertUri(string path, string originPath, string originUri) { if (path.find(originPath) != path.npos) { - if (originUri[originUri.length() - 1] == '/') { + if (originUri.length() >= 1 && originUri[originUri.length() - 1] == '/') { originUri = originUri.substr(0, originUri.length() - 1); } path.replace(0, originPath.length(), originUri); diff --git a/interfaces/kits/js/src/mod_fileio/properties/read_text.cpp b/interfaces/kits/js/src/mod_fileio/properties/read_text.cpp index 79e6b53f5471820cc2fce6b8ce6f8ef48ca396d7..9d683db798202071ba39f9c543a975ae1bf8114f 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/read_text.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/read_text.cpp @@ -99,7 +99,7 @@ napi_value ReadText::Sync(napi_env env, napi_callback_info info) return nullptr; } - len = (!hasLen || len > statbf.st_size) ? statbf.st_size : len; + len = (!hasLen || len > static_cast(statbf.st_size)) ? statbf.st_size : len; std::unique_ptr readbuf = std::make_unique(len + 1); if (readbuf == nullptr) { UniError(EINVAL).ThrowErr(env, "file is too large"); @@ -146,7 +146,7 @@ static UniError AsyncExec(const std::string &path, std::shared_ptr statbf.st_size) ? statbf.st_size : len; + len = (!hasLen || len > static_cast(statbf.st_size)) ? statbf.st_size : len; arg->buf = std::make_unique(len); if (arg->buf == nullptr) { return UniError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp index f648026d389162b5d62c4c958a50f7f6d3e22920..fc8293251dbee79ccd8a4efc4b7c5c3737414619 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp @@ -172,7 +172,7 @@ void FileWatcher::ReadNotifyEvent(WatcherCallback callback) while (index < len) { event = reinterpret_cast(buf + index); NotifyEvent(event, callback); - index += sizeof(struct inotify_event) + event->len; + index += sizeof(struct inotify_event) + static_cast(event->len); } } @@ -191,11 +191,11 @@ void FileWatcher::GetNotifyEvent(WatcherCallback callback) while (run_) { int ret = poll(fds, nfds, -1); if (ret > 0) { - if (fds[0].revents & POLLNVAL) { + if (static_cast(fds[0].revents) & POLLNVAL) { run_ = false; return; } - if (fds[1].revents & POLLIN) { + if (static_cast(fds[1].revents) & POLLIN) { ReadNotifyEvent(callback); } } else if (ret < 0 && errno == EINTR) { diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_n_exporter.cpp index 30f49cf5f93fce107ac5201e719c171790864da4..796540157878ebc99e9a89807bc46fd5a6d38543 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_n_exporter.cpp @@ -171,25 +171,27 @@ void WatcherNExporter::WatcherCallback(napi_env env, NRef &callback, const std:: HILOGE("Failed to get uv event loop"); return; } - + if (!callback) { + HILOGE("Failed to parse watcher callback"); + return; + } uv_work_t *work = new (std::nothrow) uv_work_t; if (work == nullptr) { HILOGE("Failed to create uv_work_t pointer"); return; } - if (!callback) { - HILOGE("Failed to parse watcher callback"); - return; - } - JSCallbackContext *callbackContext = new (std::nothrow) JSCallbackContext(callback); callbackContext->env_ = env; callbackContext->fileName_ = fileName; callbackContext->event_ = event; callbackContext->cookie_ = cookie; work->data = reinterpret_cast(callbackContext); - + if (work->data == nullptr) { + delete callbackContext; + delete work; + return; + } int ret = uv_queue_work( loop, work, [](uv_work_t *work) {}, reinterpret_cast(WatcherCallbackComplete)); if (ret != 0) { diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_listener/trans_listener.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_listener/trans_listener.cpp index 2d6f298001502aad3d1742ac6567c996c61f1029..2ee15ce642588802fbf86370bdc4a573abff9f3f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy_listener/trans_listener.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_listener/trans_listener.cpp @@ -176,9 +176,10 @@ void TransListener::CallbackComplete(uv_work_t *work, int stat) return; } NVal obj = NVal::CreateObject(env); - if (entry->progressSize <= numeric_limits::max() && entry->totalSize <= numeric_limits::max()) { - obj.AddProp("processedSize", NVal::CreateInt64(env, entry->progressSize).val_); - obj.AddProp("totalSize", NVal::CreateInt64(env, entry->totalSize).val_); + if (entry->progressSize <= numeric_limits::max() && + entry->totalSize <= static_cast(numeric_limits::max())) { + obj.AddProp("processedSize", NVal::CreateInt64(env, entry->progressSize).val_); + obj.AddProp("totalSize", NVal::CreateInt64(env, entry->totalSize).val_); } napi_value result = nullptr; diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index 3d7b0ecae10493f8d6d6688900b5247962d5af22..b6184e366ad50b7bad84f8ba715e9ef7158a51fd 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -85,7 +85,7 @@ static int GetMode(NVal secondVar, bool *hasMode) int mode = 0; *hasMode = true; tie(succ, mode) = secondVar.ToInt32(); - if (succ && (mode & 0x06) == mode) { + if (succ && (static_cast(mode) & 0x06) == static_cast(mode)) { return mode; } } diff --git a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp index 3df058b8546c7bbaf23451aaad86018686188ecc..d74cb0a270f30606450d33996df4941568614cdc 100644 --- a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp +++ b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp @@ -51,7 +51,10 @@ NAsyncWorkCallback::~NAsyncWorkCallback() return; } work->data = static_cast(ctx_); - + if (work->data == nullptr) { + HILOGE("Failed to allocate memory for uv_work_t data"); + return; + } int ret = uv_queue_work( loop, work.get(), [](uv_work_t *work) {}, [](uv_work_t *work, int status) {