[libcxx-commits] [libcxx] [libc++][hardening] Use bounded iterators in std::vector and std::string (PR #78929)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 21 20:10:00 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff b1d4265a5f5345065e5c2aedf50787da05ddcc08 acb2ee01c7c27bfea9e3b91a33ab5d8ddb0b1d6c -- libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.invalidation.pass.cpp libcxx/include/__iterator/bounded_iter.h libcxx/include/string libcxx/include/vector libcxx/test/libcxx/containers/sequences/vector/debug.iterator.add.pass.cpp libcxx/test/libcxx/containers/sequences/vector/debug.iterator.decrement.pass.cpp libcxx/test/libcxx/containers/sequences/vector/debug.iterator.dereference.pass.cpp libcxx/test/libcxx/containers/sequences/vector/debug.iterator.increment.pass.cpp libcxx/test/libcxx/containers/sequences/vector/debug.iterator.index.pass.cpp libcxx/test/libcxx/containers/views/views.span/debug.iterator-indexing.pass.cpp libcxx/test/libcxx/iterators/bounded_iter/dereference.pass.cpp libcxx/test/libcxx/strings/basic.string/alignof.compile.pass.cpp libcxx/test/libcxx/strings/basic.string/sizeof.compile.pass.cpp libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.add.pass.cpp libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.decrement.pass.cpp libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.dereference.pass.cpp libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.increment.pass.cpp libcxx/test/libcxx/strings/basic.string/string.iterators/debug.iterator.index.pass.cpp libcxx/test/libcxx/strings/string.view/string.view.iterators/debug.iterator-indexing.pass.cpp libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.pass.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.invalidation.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.invalidation.pass.cpp
index 4ab70821d3..a0d6570649 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.invalidation.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.invalidation.pass.cpp
@@ -18,26 +18,25 @@
 #include <cassert>
 #include <cstddef>
 
-int main(int, char**)
-{
-    std::vector<int> vec;
-    vec.push_back(0);
-    vec.push_back(1);
-    vec.push_back(2);
-    vec.reserve(4);
-    std::size_t old_capacity = vec.capacity();
-    assert(old_capacity >= 4);
+int main(int, char**) {
+  std::vector<int> vec;
+  vec.push_back(0);
+  vec.push_back(1);
+  vec.push_back(2);
+  vec.reserve(4);
+  std::size_t old_capacity = vec.capacity();
+  assert(old_capacity >= 4);
 
-    auto it = vec.begin();
-    vec.push_back(3);
-    assert(vec.capacity() == old_capacity);
+  auto it = vec.begin();
+  vec.push_back(3);
+  assert(vec.capacity() == old_capacity);
 
-    // The capacity did not change, so the iterator remains valid and can reach
-    // the new element.
-    assert(*it == 0);
-    assert(*(it + 1) == 1);
-    assert(*(it + 2) == 2);
-    assert(*(it + 3) == 3);
+  // The capacity did not change, so the iterator remains valid and can reach
+  // the new element.
+  assert(*it == 0);
+  assert(*(it + 1) == 1);
+  assert(*(it + 2) == 2);
+  assert(*(it + 3) == 3);
 
-    return 0;
+  return 0;
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/78929


More information about the libcxx-commits mailing list