[clang-tools-extra] [NFC] Fix potential underflow constant. (PR #118528)

Zahira Ammarguellat via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 3 10:55:01 PST 2024


https://github.com/zahiraam created https://github.com/llvm/llvm-project/pull/118528

None

>From 59904d85cece9758dbb449ae4180ee5f917d0263 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <Zahira.Ammarguellat at intel.com>
Date: Tue, 3 Dec 2024 10:53:22 -0800
Subject: [PATCH] [NFC] Fix potential underflow constant.

---
 .../bugprone/CrtpConstructorAccessibilityCheck.cpp        | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
index 8eaf54fe0088a4..ce307a2384aef7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
@@ -58,10 +58,10 @@ getDerivedParameter(const ClassTemplateSpecializationDecl *CRTP,
                Arg.getAsType()->getAsCXXRecordDecl() == Derived;
       });
 
-  return AnyOf ? CRTP->getSpecializedTemplate()
-                     ->getTemplateParameters()
-                     ->getParam(Idx - 1)
-               : nullptr;
+  return AnyOf && Idx > 0 ? CRTP->getSpecializedTemplate()
+                                ->getTemplateParameters()
+                                ->getParam(Idx - 1)
+                          : nullptr;
 }
 
 static std::vector<FixItHint>



More information about the cfe-commits mailing list