Index: llvm/lib/Support/Unix/Path.inc =================================================================== --- llvm/lib/Support/Unix/Path.inc +++ llvm/lib/Support/Unix/Path.inc @@ -380,20 +380,22 @@ return std::error_code(); } - result.reserve(PATH_MAX); + result.resize_for_overwrite(PATH_MAX); while (true) { - if (::getcwd(result.data(), result.capacity()) == nullptr) { + if (::getcwd(result.data(), result.size()) == nullptr) { // See if there was a real error. - if (errno != ENOMEM) + if (errno != ENOMEM) { + result.clear(); return std::error_code(errno, std::generic_category()); + } // Otherwise there just wasn't enough space. - result.reserve(result.capacity() * 2); + result.resize_for_overwrite(result.capacity() * 2); } else break; } - result.set_size(strlen(result.data())); + result.truncate(strlen(result.data())); return std::error_code(); }