[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
Tue Jan 11 18:00:37 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0492d92adc5: Support: Avoid SmallVector::set_size() in Unix code (authored by dexonsmith).

Repository:
  rG LLVM Github Monorepo

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.399151.patch
Type: text/x-patch
Size: 963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220112/791e9c35/attachment.bin>


More information about the llvm-commits mailing list