r334560 - [analyzer] Do not crash in the visitor when the function is given more arguments than it has parameters

George Karpenkov via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 12 16:53:54 PDT 2018


Author: george.karpenkov
Date: Tue Jun 12 16:53:54 2018
New Revision: 334560

URL: http://llvm.org/viewvc/llvm-project?rev=334560&view=rev
Log:
[analyzer] Do not crash in the visitor when the function is given more arguments than it has parameters

rdar://40335545

Differential Revision: https://reviews.llvm.org/D48107

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

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=334560&r1=334559&r2=334560&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue Jun 12 16:53:54 2018
@@ -286,7 +286,7 @@ public:
     }
 
     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;

Modified: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp?rev=334560&r1=334559&r2=334560&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp Tue Jun 12 16:53:54 2018
@@ -145,3 +145,18 @@ int usepointerreference() {
   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;
+}




More information about the cfe-commits mailing list