[clang] [-Wunsafe-buffer-usage] Fix false positives for string literals (PR #115554)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 8 14:16:52 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 8a7a7b5ffc690bd012cf090d31d47ec938248ba3 8db304f11ba708abd096b4b8df998c55548e5b4d --extensions cpp -- clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp clang/lib/Analysis/UnsafeBufferUsage.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 116d098075..65a4fecd54 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -436,7 +436,7 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
APInt ArrSize{};
if (const auto *BaseDRE =
- dyn_cast<DeclRefExpr>(Node.getBase()->IgnoreParenImpCasts())) {
+ dyn_cast<DeclRefExpr>(Node.getBase()->IgnoreParenImpCasts())) {
if (!BaseDRE)
return false;
if (!BaseDRE->getDecl())
@@ -446,7 +446,8 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
if (!CATy)
return false;
ArrSize = CATy->getSize();
- } else if (const auto *BaseStrLit = dyn_cast<StringLiteral>(Node.getBase()->IgnoreParenImpCasts())) {
+ } else if (const auto *BaseStrLit = dyn_cast<StringLiteral>(
+ Node.getBase()->IgnoreParenImpCasts())) {
// Add 1 for the terminating null character.
ArrSize = APInt{64, BaseStrLit->getLength() + 1, false};
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/115554
More information about the cfe-commits
mailing list