Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Basic/FileManager.cpp
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | |||||
FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) { | FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) { | ||||
// stat doesn't like trailing separators except for root directory. | // stat doesn't like trailing separators except for root directory. | ||||
// At least, on Win32 MSVCRT, stat() cannot strip trailing '/'. | // At least, on Win32 MSVCRT, stat() cannot strip trailing '/'. | ||||
// (though it can strip '\\') | // (though it can strip '\\') | ||||
if (DirName.size() > 1 && | if (DirName.size() > 1 && | ||||
DirName != llvm::sys::path::root_path(DirName) && | DirName != llvm::sys::path::root_path(DirName) && | ||||
llvm::sys::path::is_separator(DirName.back())) | llvm::sys::path::is_separator(DirName.back())) | ||||
DirName = DirName.substr(0, DirName.size()-1); | DirName = DirName.substr(0, DirName.size()-1); | ||||
#ifdef _WIN32 | if (is_style_windows(llvm::sys::path::Style::native)) { | ||||
// Fixing a problem with "clang C:test.c" on Windows. | // Fixing a problem with "clang C:test.c" on Windows. | ||||
// Stat("C:") does not recognize "C:" as a valid directory | // Stat("C:") does not recognize "C:" as a valid directory | ||||
std::string DirNameStr; | std::string DirNameStr; | ||||
if (DirName.size() > 1 && DirName.back() == ':' && | if (DirName.size() > 1 && DirName.back() == ':' && | ||||
DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) { | DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) { | ||||
DirNameStr = DirName.str() + '.'; | DirNameStr = DirName.str() + '.'; | ||||
DirName = DirNameStr; | DirName = DirNameStr; | ||||
dexonsmith: This introduced a use-after-scope for DirNameStr. Fixed in… | |||||
} | } | ||||
#endif | } | ||||
++NumDirLookups; | ++NumDirLookups; | ||||
// See if there was already an entry in the map. Note that the map | // See if there was already an entry in the map. Note that the map | ||||
// contains both virtual and real directories. | // contains both virtual and real directories. | ||||
auto SeenDirInsertResult = | auto SeenDirInsertResult = | ||||
SeenDirEntries.insert({DirName, std::errc::no_such_file_or_directory}); | SeenDirEntries.insert({DirName, std::errc::no_such_file_or_directory}); | ||||
if (!SeenDirInsertResult.second) { | if (!SeenDirInsertResult.second) { | ||||
▲ Show 20 Lines • Show All 517 Lines • Show Last 20 Lines |
This introduced a use-after-scope for DirNameStr. Fixed in 9091df5fad52ab6a281d7f4d6a508696e6f9fbae.