[clang] [NFC][Clang][SafeBuffers] Correct naming (sz -> size). (PR #180629)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 13:49:27 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Rohan Jacob-Rao (rohanjr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/180629.diff
1 Files Affected:
- (modified) clang/docs/SafeBuffers.rst (+5-5)
``````````diff
diff --git a/clang/docs/SafeBuffers.rst b/clang/docs/SafeBuffers.rst
index 205e621e9d0eb..a11fc317736cf 100644
--- a/clang/docs/SafeBuffers.rst
+++ b/clang/docs/SafeBuffers.rst
@@ -135,7 +135,7 @@ the only formal "hint" in the program that the pointer does indeed point
to a buffer of multiple objects::
int get_last_element(int *pointer, size_t size) {
- return ptr[sz - 1]; // warning: unsafe buffer access
+ return ptr[size - 1]; // warning: unsafe buffer access
}
int *get_last_element_ptr(int *pointer, size_t size) {
@@ -177,9 +177,9 @@ section can be made **slightly** safer this way::
}
Here ``std::span`` eliminates the potential concern that the operation
-``size - 1`` may overflow when ``sz`` is equal to ``0``, leading to a buffer
+``size - 1`` may overflow when ``size`` is equal to ``0``, leading to a buffer
"underrun". However, such program does not provide a guarantee that
-the variable ``sz`` correctly represents the **actual** size fo the buffer
+the variable ``size`` correctly represents the **actual** size fo the buffer
pointed to by ``ptr``. The ``std::span`` constructed this way may be ill-formed.
It may fail to protect you from overrunning the original buffer.
@@ -320,7 +320,7 @@ here is how you can suppress it::
int get_last_element(int *pointer, size_t size) {
#pragma clang unsafe_buffer_usage begin
- return ptr[sz - 1]; // warning suppressed
+ return ptr[size - 1]; // warning suppressed
#pragma clang unsafe_buffer_usage end
}
@@ -484,7 +484,7 @@ and undesirable than the previous solution::
// This access is still completely unchecked. What's the point of having
// perfect bounds information if you aren't performing runtime checks?
#pragma clang unsafe_buffer_usage begin
- return ptr[sz - 1];
+ return ptr[size - 1];
#pragma clang unsafe_buffer_usage end
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/180629
More information about the cfe-commits
mailing list