From acf4da93857acc9ac1fb48e89c82c039c16e87e2 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Tue, 18 Dec 2012 16:45:18 +0100 Subject: [PATCH] Fixes for some minor bugs clang-analyzer and cppcheck found Signed-off-by: Dale Weiler --- ast.c | 2 +- gmqcc.h | 2 +- ir.c | 12 ++++++++---- lexer.c | 1 - parser.c | 16 +++++++--------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ast.c b/ast.c index 68a8eac..58206cc 100644 --- a/ast.c +++ b/ast.c @@ -2152,7 +2152,7 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va ir_value *condval; ir_value *dummy; - ir_block *cond = func->curblock; + ir_block *cond; ir_block *ontrue; ir_block *onfalse; ir_block *ontrue_endblock = NULL; diff --git a/gmqcc.h b/gmqcc.h index df123c6..e2878f9 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -116,7 +116,7 @@ * I suspect it also has just __inline of some sort, but our use * of inline is correct (not guessed), WE WANT IT TO BE INLINE */ -#elseif defined(_MSC_VER) +#elif defined(_MSC_VER) # define GMQCC_INLINE __forceinline #else # define GMQCC_INLINE diff --git a/ir.c b/ir.c index 2375d55..defbd40 100644 --- a/ir.c +++ b/ir.c @@ -1357,9 +1357,6 @@ bool ir_block_create_store_op(ir_block *self, lex_ctx ctx, int op, ir_value *tar irerror(self->context, "unreachable statement (%s)", self->label); return false; } - in = ir_instr_new(ctx, self, op); - if (!in) - return false; if (target->store == store_value && (op < INSTR_STOREP_F || op > INSTR_STOREP_FNC)) @@ -1370,9 +1367,14 @@ bool ir_block_create_store_op(ir_block *self, lex_ctx ctx, int op, ir_value *tar return false; } + in = ir_instr_new(ctx, self, op); + if (!in) + return false; + if (!ir_instr_op(in, 0, target, true) || !ir_instr_op(in, 1, what, false)) { + ir_instr_delete(in); return false; } vec_push(self->instr, in); @@ -1439,8 +1441,10 @@ bool ir_block_create_return(ir_block *self, lex_ctx ctx, ir_value *v) if (!in) return false; - if (v && !ir_instr_op(in, 0, v, false)) + if (v && !ir_instr_op(in, 0, v, false)) { + ir_instr_delete(in); return false; + } vec_push(self->instr, in); return true; diff --git a/lexer.c b/lexer.c index 6f8853d..c25dd09 100644 --- a/lexer.c +++ b/lexer.c @@ -1061,7 +1061,6 @@ int lex_do(lex_file *lex) if (rc < 0) return (lex->tok.ttype = TOKEN_FATAL); - v = lex->tok.value; if (lex->modelname) { frame_macro m; m.value = lex->framevalue; diff --git a/parser.c b/parser.c index e747626..d329335 100644 --- a/parser.c +++ b/parser.c @@ -1275,9 +1275,9 @@ static bool parser_close_call(parser_t *parser, shunt *sy) fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line); else parseerror(parser, "too %s parameters for function call: expected %i, got %i\n" - " -> `%s` has been declared here: %s:%i", - fewmany, fval->name, (int)vec_size(fun->expression.params), (int)paramcount, - fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line); + " -> it has been declared here: %s:%i", + fewmany, (int)vec_size(fun->expression.params), (int)paramcount, + ast_ctx(fun).file, (int)ast_ctx(fun).line); return false; } else @@ -1291,9 +1291,9 @@ static bool parser_close_call(parser_t *parser, shunt *sy) else return !parsewarning(parser, WARN_TOO_FEW_PARAMETERS, "too %s parameters for function call: expected %i, got %i\n" - " -> `%s` has been declared here: %s:%i", - fewmany, fval->name, (int)vec_size(fun->expression.params), (int)paramcount, - fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line); + " -> it has been declared here: %s:%i", + fewmany, (int)vec_size(fun->expression.params), (int)paramcount, + ast_ctx(fun).file, (int)ast_ctx(fun).line); } } } @@ -1698,7 +1698,6 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma vec_push(sy.ops, syparen(parser_ctx(parser), SY_PAREN_INDEX, 0)); wantop = false; } else if (op->id == opid2('?',':')) { - wantop = false; vec_push(sy.ops, syop(parser_ctx(parser), op)); vec_push(sy.ops, syparen(parser_ctx(parser), SY_PAREN_TERNARY, 0)); wantop = false; @@ -2339,8 +2338,7 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou return false; } if (!OPTS_FLAG(RELAXED_SWITCH)) { - opval = (ast_value*)swcase.value; - if (!ast_istype(swcase.value, ast_value)) { /* || opval->cvq != CV_CONST) { */ + if (!ast_istype(swcase.value, ast_value)) { /* || ((ast_value*)swcase.value)->cvq != CV_CONST) { */ parseerror(parser, "case on non-constant values need to be explicitly enabled via -frelaxed-switch"); ast_unref(operand); return false; -- 2.39.2