Commit d39c5f3d authored by Andrew Krieger's avatar Andrew Krieger Committed by Facebook Github Bot

Fix portability opendir() behavior on paths without trailing slashes

Summary:
Off-by-one error in DIR::open() would result in paths not
ending in a trailing separator to fail to open. Fix the arithmetic.

Reviewed By: Orvid

Differential Revision: D5579657

fbshipit-source-id: 79507bc398549033eb26b2ffa788d66241deb623
parent b3aabafd
......@@ -37,10 +37,18 @@ struct DIR {
wchar_t patternBuf[MAX_PATH + 3];
size_t len;
if (pattern.empty()) {
return nullptr;
}
if (mbstowcs_s(&len, patternBuf, MAX_PATH, pattern.c_str(), MAX_PATH - 2)) {
return nullptr;
}
// `len` includes the trailing NUL
if (len) {
len--;
}
if (len && patternBuf[len - 1] != '/' && patternBuf[len - 1] != '\\') {
patternBuf[len++] = '\\';
}
......
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