[PATCH] D115389: Support: Avoid SmallVector::set_size() in Unix code
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 8 16:33:58 PST 2021
dexonsmith updated this revision to Diff 392976.
dexonsmith added reviewers: mstorsjo, dblaikie, Bigcheese.
dexonsmith added a comment.
Adding a couple of potential reviewers.
[No change in diff; just retrigging CI after a spurious failure.]
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115389/new/
https://reviews.llvm.org/D115389
Files:
llvm/lib/Support/Unix/Path.inc
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();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115389.392976.patch
Type: text/x-patch
Size: 963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211209/b449de49/attachment.bin>
More information about the llvm-commits
mailing list