[analyzer] Fix crash in NullabilityChecker calling block with too few arguments

Fix a crash when checking parameter nullability on a block invocation
with fewer arguments than the block declaration requires.

rdar://problem/29237566

llvm-svn: 286901
This commit is contained in:
Devin Coughlin 2016-11-14 22:46:02 +00:00
parent aaa06fa486
commit e4224cc9f7
2 changed files with 16 additions and 3 deletions

View File

@ -679,9 +679,10 @@ void NullabilityChecker::checkPreCall(const CallEvent &Call,
if (Param->isParameterPack())
break;
const Expr *ArgExpr = nullptr;
if (Idx < Call.getNumArgs())
ArgExpr = Call.getArgExpr(Idx);
if (Idx >= Call.getNumArgs())
break;
const Expr *ArgExpr = Call.getArgExpr(Idx);
auto ArgSVal = Call.getArgSVal(Idx++).getAs<DefinedOrUnknownSVal>();
if (!ArgSVal)
continue;

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -fblocks -analyze -analyzer-checker=core,nullability -verify %s
void it_takes_two(int a, int b);
void function_pointer_arity_mismatch() {
void(*fptr)() = it_takes_two;
fptr(1); // no-crash expected-warning {{Function taking 2 arguments is called with less (1)}}
}
void block_arity_mismatch() {
void(^b)() = ^(int a, int b) { }; // no-crash
b(1);
}