wreaddir_resolving: Don't add "/" for empty paths

This could end up trying to `stat()` a file in /, like "/glassdoor",
if the dir_path was empty.
This commit is contained in:
Fabian Boehm 2022-09-20 16:29:34 +02:00
parent 88e578a9ed
commit 8b9a051b93

@ -76,7 +76,11 @@ bool wreaddir_resolving(DIR *dir, const wcstring &dir_path, wcstring &out_name,
if (check_with_stat) {
// We couldn't determine the file type from the dirent; check by stat'ing it.
cstring fullpath = wcs2string(dir_path);
fullpath.push_back('/');
if (!fullpath.empty()) {
// If the dir_path was empty, we just use the name.
// This ends up as a relative path which is fine.
fullpath.push_back('/');
}
fullpath.append(result->d_name);
struct stat buf;
if (stat(fullpath.c_str(), &buf) != 0) {