Commit 7e5da6c6 authored by Chen Bill's avatar Chen Bill Committed by GitHub

fix warning -Wformat-truncation (#2613)

parent 79be003f
...@@ -174,8 +174,12 @@ public: ...@@ -174,8 +174,12 @@ public:
static bool DeleteDir(const char* dir) { static bool DeleteDir(const char* dir) {
bool success = true; bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) { TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
char full_path[256]; char full_path[1024];
snprintf(full_path, sizeof full_path, "%s/%s", dir, name); int len = std::snprintf(full_path, sizeof full_path, "%s/%s", dir, name);
if (len < 0 || len >= (int)(sizeof full_path)) {
success = false;
return;
}
if (isdir) if (isdir)
{ {
if(!DeleteDir(full_path)) if(!DeleteDir(full_path))
...@@ -207,7 +211,9 @@ public: ...@@ -207,7 +211,9 @@ public:
while((dirp = readdir(dir)) != nullptr) { while((dirp = readdir(dir)) != nullptr) {
file_unit funit; file_unit funit;
char fname[1024]; char fname[1024];
std::snprintf(fname, sizeof fname, "%s/%s", path, dirp->d_name); int len = std::snprintf(fname, sizeof fname, "%s/%s", path, dirp->d_name);
if (len < 0 || len >= (int)(sizeof fname))
continue;
stat(fname, &fileStat); stat(fname, &fileStat);
funit.filename = std::string(dirp->d_name); funit.filename = std::string(dirp->d_name);
funit.is_dir = S_ISDIR(fileStat.st_mode); funit.is_dir = S_ISDIR(fileStat.st_mode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment