[PATCH] D48107: [analyzer] Do not crash in the visitor when the function is given more arguments than it has parameters

George Karpenkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 12 16:58:20 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL334560: [analyzer] Do not crash in the visitor when the function is given moreā€¦ (authored by george.karpenkov, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48107?vs=151069&id=151072#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48107

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp


Index: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
===================================================================
--- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
+++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
@@ -145,3 +145,18 @@
   return s.x; // expected-warning{{Undefined or garbage value returned to caller}}
               // expected-note at -1{{Undefined or garbage value returned to caller}}
 }
+
+void *has_no_argument_and_returns_null(void) {
+  return 0;
+}
+
+void rdar40335545() {
+    int local; // expected-note{{}}
+    void (*takes_int_ptr_argument)(int *) = (void (*)(int*))has_no_argument_and_returns_null;
+
+    takes_int_ptr_argument(&local); // no-crash
+
+    int useLocal = local; //expected-warning{{}}
+                          //expected-note at -1{{}}
+    (void)useLocal;
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -286,7 +286,7 @@
     }
 
     ArrayRef<ParmVarDecl *> parameters = getCallParameters(Call);
-    for (unsigned I = 0, E = Call->getNumArgs(); I != E; ++I) {
+    for (unsigned I = 0; I < Call->getNumArgs() && I < parameters.size(); ++I) {
       const ParmVarDecl *PVD = parameters[I];
       SVal S = Call->getArgSVal(I);
       unsigned IndirectionLevel = 1;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48107.151072.patch
Type: text/x-patch
Size: 1492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180612/9b7aab16/attachment.bin>


More information about the llvm-commits mailing list