[clang] [NFC][Clang] Fix potential deref of end iterator (PR #70193)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 26 02:54:40 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Nathan Gauër (Keenuts)

<details>
<summary>Changes</summary>

This was found by doing bound-checking on SmallVector iterator usage. When the count is 0, the end iterator is dereferenced to get its address. This doesn't seem to be an issue in practice as most of the time we should be allowed to deref this address, but I don't think this is correct.

---
Full diff: https://github.com/llvm/llvm-project/pull/70193.diff


1 Files Affected:

- (modified) clang/include/clang/Sema/CXXFieldCollector.h (+1-1) 


``````````diff
diff --git a/clang/include/clang/Sema/CXXFieldCollector.h b/clang/include/clang/Sema/CXXFieldCollector.h
index f6ecd9f46e5ebdb..ce066581c93fda7 100644
--- a/clang/include/clang/Sema/CXXFieldCollector.h
+++ b/clang/include/clang/Sema/CXXFieldCollector.h
@@ -65,7 +65,7 @@ class CXXFieldCollector {
 
   /// getCurFields - Pointer to array of fields added to the currently parsed
   /// class.
-  FieldDecl **getCurFields() { return &*(Fields.end() - getCurNumFields()); }
+  FieldDecl **getCurFields() { return Fields.end() - getCurNumFields(); }
 
   /// FinishClass - Called by Sema::ActOnFinishCXXClassDef.
   void FinishClass() {

``````````

</details>


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


More information about the cfe-commits mailing list