r199571 - Harden InitListExpr::isStringLiteralInit() against getInit() returning null.
Ted Kremenek
kremenek at apple.com
Sat Jan 18 22:31:35 PST 2014
Author: kremenek
Date: Sun Jan 19 00:31:34 2014
New Revision: 199571
URL: http://llvm.org/viewvc/llvm-project?rev=199571&view=rev
Log:
Harden InitListExpr::isStringLiteralInit() against getInit() returning null.
This led to a crash on invalid code (sorry, no good test case).
Fixes <rdar://problem/15831804>.
Modified:
cfe/trunk/lib/AST/Expr.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=199571&r1=199570&r2=199571&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Jan 19 00:31:34 2014
@@ -1869,7 +1869,11 @@ bool InitListExpr::isStringLiteralInit()
const ArrayType *AT = getType()->getAsArrayTypeUnsafe();
if (!AT || !AT->getElementType()->isIntegerType())
return false;
- const Expr *Init = getInit(0)->IgnoreParens();
+ // It is possible for getInit() to return null.
+ const Expr *Init = getInit(0);
+ if (!Init)
+ return false;
+ Init = Init->IgnoreParens();
return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init);
}
More information about the cfe-commits
mailing list