diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index 2ba4834b8fdfc3eb7b94907385118ed84eba3980..f4b80b4b6006e094a98ab2ce7184baefd23ed946 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -202,7 +202,9 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) } else if (string(res->d_name) == "." || string(res->d_name) == "..") { continue; } else { - tmpDirent = *res; + if (EOK != memcpy_s(&tmpDirent, sizeof(dirent), res, res->d_reclen)) { + return UniError(errno); + } break; } } while (true); @@ -275,7 +277,10 @@ napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) } else if (string(res->d_name) == "." || string(res->d_name) == "..") { continue; } else { - tmpDirent = *res; + if (EOK != memcpy_s(&tmpDirent, sizeof(dirent), res, res->d_reclen)) { + UniError(errno).ThrowErr(env); + return nullptr; + } break; } } while (true);