From: Dale Weiler Date: Fri, 21 Jun 2013 23:21:12 +0000 (+0000) Subject: Fix possible NULL pointer dereference X-Git-Tag: v0.3.0~98 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=996d998ebbede68ff624ace1b2b5c291cb361280;p=xonotic%2Fgmqcc.git Fix possible NULL pointer dereference --- diff --git a/ast.c b/ast.c index f814847..913e852 100644 --- a/ast.c +++ b/ast.c @@ -1152,16 +1152,15 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) { ast_instantiate(ast_function, ctx, ast_function_delete); - if (!vtype || - vtype->hasvalue || - vtype->expression.vtype != TYPE_FUNCTION) - { + if (!vtype) { + compile_error(ast_ctx(self), "internal error: ast_function_new condition 0"); + goto cleanup; + } else if (vtype->hasvalue || vtype->expression.vtype != TYPE_FUNCTION) { compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)", (int)!vtype, (int)vtype->hasvalue, vtype->expression.vtype); - mem_d(self); - return NULL; + goto cleanup; } self->vtype = vtype; @@ -1186,6 +1185,10 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) self->return_value = NULL; return self; + +cleanup: + mem_d(self); + return NULL; } void ast_function_delete(ast_function *self)