Skip to content

Commit 37410a3

Browse files
committed
Fixed warning by deepcode
1 parent 6e20e66 commit 37410a3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/wsjcpp_core.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,19 @@ std::vector<std::string> WsjcppCore::getListOfFiles(const std::string &sDirname)
299299
return vFiles;
300300
}
301301
DIR *dir = opendir(sDirname.c_str());
302-
struct dirent *entry = readdir(dir);
303-
while (entry != NULL) {
304-
if (entry->d_type != DT_DIR) {
305-
std::string sDir(entry->d_name);
306-
if (sDir != "." && sDir != "..") {
307-
vFiles.push_back(sDir);
302+
if (dir != NULL) {
303+
struct dirent *entry = readdir(dir);
304+
while (entry != NULL) {
305+
if (entry->d_type != DT_DIR) {
306+
std::string sDir(entry->d_name);
307+
if (sDir != "." && sDir != "..") {
308+
vFiles.push_back(sDir);
309+
}
308310
}
311+
entry = readdir(dir);
309312
}
310-
entry = readdir(dir);
313+
closedir(dir);
311314
}
312-
closedir(dir);
313315
return vFiles;
314316
}
315317

0 commit comments

Comments
 (0)