Add missing "$$=NULL;" in error production in parser.
This fixes a crash from a malformed program bug.
This commit is contained in:
4
expr.cpp
4
expr.cpp
@@ -1899,8 +1899,8 @@ static void
|
|||||||
lPrintPassedTypes(const char *funName, const std::vector<Expr *> &argExprs) {
|
lPrintPassedTypes(const char *funName, const std::vector<Expr *> &argExprs) {
|
||||||
fprintf(stderr, "Passed types:\n\t%s(", funName);
|
fprintf(stderr, "Passed types:\n\t%s(", funName);
|
||||||
for (unsigned int i = 0; i < argExprs.size(); ++i) {
|
for (unsigned int i = 0; i < argExprs.size(); ++i) {
|
||||||
const Type *t = argExprs[i]->GetType();
|
const Type *t;
|
||||||
if (t)
|
if (argExprs[i] != NULL && (t = argExprs[i]->GetType()) != NULL)
|
||||||
fprintf(stderr, "%s%s", t->GetString().c_str(),
|
fprintf(stderr, "%s%s", t->GetString().c_str(),
|
||||||
(i < argExprs.size()-1) ? ", " : ")\n\n");
|
(i < argExprs.size()-1) ? ", " : ")\n\n");
|
||||||
else
|
else
|
||||||
|
|||||||
1
parse.yy
1
parse.yy
@@ -927,6 +927,7 @@ statement
|
|||||||
std::vector<std::string> alternates = MatchStrings(yytext, builtinTokens);
|
std::vector<std::string> alternates = MatchStrings(yytext, builtinTokens);
|
||||||
std::string alts = lGetAlternates(alternates);
|
std::string alts = lGetAlternates(alternates);
|
||||||
Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str());
|
Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str());
|
||||||
|
$$ = NULL;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
11
stmt.cpp
11
stmt.cpp
@@ -239,6 +239,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Symbol *sym = decl->sym;
|
Symbol *sym = decl->sym;
|
||||||
|
assert(decl->sym != NULL);
|
||||||
const Type *type = sym->type;
|
const Type *type = sym->type;
|
||||||
if (!type)
|
if (!type)
|
||||||
continue;
|
continue;
|
||||||
@@ -280,6 +281,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const llvm::Type *llvmType = type->LLVMType(g->ctx);
|
const llvm::Type *llvmType = type->LLVMType(g->ctx);
|
||||||
|
assert(llvmType != NULL);
|
||||||
|
|
||||||
if (declaration->declSpecs->storageClass == SC_STATIC) {
|
if (declaration->declSpecs->storageClass == SC_STATIC) {
|
||||||
// For static variables, we need a compile-time constant value
|
// For static variables, we need a compile-time constant value
|
||||||
@@ -353,11 +355,16 @@ DeclStmt::Optimize() {
|
|||||||
|
|
||||||
Stmt *
|
Stmt *
|
||||||
DeclStmt::TypeCheck() {
|
DeclStmt::TypeCheck() {
|
||||||
|
bool encounteredError = false;
|
||||||
for (unsigned int i = 0; i < declaration->declarators.size(); ++i) {
|
for (unsigned int i = 0; i < declaration->declarators.size(); ++i) {
|
||||||
Declarator *decl = declaration->declarators[i];
|
Declarator *decl = declaration->declarators[i];
|
||||||
if (!decl || !decl->initExpr)
|
if (!decl) {
|
||||||
|
encounteredError = true;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!decl->initExpr)
|
||||||
|
continue;
|
||||||
decl->initExpr = decl->initExpr->TypeCheck();
|
decl->initExpr = decl->initExpr->TypeCheck();
|
||||||
if (!decl->initExpr)
|
if (!decl->initExpr)
|
||||||
continue;
|
continue;
|
||||||
@@ -374,7 +381,7 @@ DeclStmt::TypeCheck() {
|
|||||||
decl->initExpr = decl->initExpr->TypeConv(type, "initializer");
|
decl->initExpr = decl->initExpr->TypeConv(type, "initializer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return encounteredError ? NULL : this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user