]> granicus.if.org Git - clang/commitdiff
[analyzer] Do not crash in the visitor when the function is given more arguments...
authorGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 12 Jun 2018 23:53:54 +0000 (23:53 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 12 Jun 2018 23:53:54 +0000 (23:53 +0000)
rdar://40335545

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334560 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 3cac6cb328412727a56f49827e700f02f8d5e66e..fceb3f094ca279384ee626face2da6f2ad8af020 100644 (file)
@@ -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;
index a704c14c251dffa59ea64ab85c61f69df7d9af52..b96dc4cf2a8568c90fe7438aa04eba8ce524aa73 100644 (file)
@@ -145,3 +145,18 @@ int usepointerreference() {
   return s.x; // expected-warning{{Undefined or garbage value returned to caller}}
               // expected-note@-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@-1{{}}
+    (void)useLocal;
+}