From: Eli Friedman Date: Sat, 14 Nov 2009 04:43:10 +0000 (+0000) Subject: PR5462: Don't run off the edge of the argument array for vararg handling X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e42ffd3a848236413caa799f1f32a87fd6d702b;p=clang PR5462: Don't run off the edge of the argument array for vararg handling when there are more parameters in the prototype than arguments to the call. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88759 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index f20b37d90c..b311fda2d3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2679,7 +2679,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, CallType = VariadicMethod; // Promote the arguments (C99 6.5.2.2p7). - for (unsigned i = NumArgsInProto; i != NumArgs; i++) { + for (unsigned i = NumArgsInProto; i < NumArgs; i++) { Expr *Arg = Args[i]; Invalid |= DefaultVariadicArgumentPromotion(Arg, CallType); Call->setArg(i, Arg); diff --git a/test/SemaCXX/vararg-default-arg.cpp b/test/SemaCXX/vararg-default-arg.cpp new file mode 100644 index 0000000000..5ba0320277 --- /dev/null +++ b/test/SemaCXX/vararg-default-arg.cpp @@ -0,0 +1,10 @@ +// RUN: clang-cc %s -verify -fsyntax-only +// PR5462 + +void f1(void); +void f2(const char * = __null, ...); + +void f1(void) +{ + f2(); +}