From: George Karpenkov Date: Tue, 12 Jun 2018 23:53:54 +0000 (+0000) Subject: [analyzer] Do not crash in the visitor when the function is given more arguments... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b28c0c543c93e5ada9127947a0adc91c8fd00331;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334560 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 3cac6cb328..fceb3f094c 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -286,7 +286,7 @@ public: } ArrayRef 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; diff --git a/test/Analysis/diagnostics/no-store-func-path-notes.cpp b/test/Analysis/diagnostics/no-store-func-path-notes.cpp index a704c14c25..b96dc4cf2a 100644 --- a/test/Analysis/diagnostics/no-store-func-path-notes.cpp +++ b/test/Analysis/diagnostics/no-store-func-path-notes.cpp @@ -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; +}