]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Fixes for some minor bugs clang-analyzer and cppcheck found
authorRudolf Polzer <divverent@xonotic.org>
Tue, 18 Dec 2012 15:45:18 +0000 (16:45 +0100)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 18 Dec 2012 16:54:51 +0000 (16:54 +0000)
Signed-off-by: Dale Weiler <killfieldengine@gmail.com>
ast.c
gmqcc.h
ir.c
lexer.c
parser.c

diff --git a/ast.c b/ast.c
index 68a8eaccf0f6b7ef6c7303b56bbb2e70218aaba1..58206ccc0b5a09810110e7154e81f6709db1de86 100644 (file)
--- 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 df123c6c42713c733446ee21c1eb8c1773cf4409..e2878f9b5eeb1e6f8ea308ed79b1148ad5820128 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
  * 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 2375d55368c40d0d52c5e194f70f39a1439622b2..defbd407ca6e153cf2b0594ed4156aeff8805048 100644 (file)
--- 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 6f8853d453acf132de13f7de4894a578040cda19..c25dd0951a2a901804d85d19c60082c26c769348 100644 (file)
--- 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;
index e747626724394206a780bc040bd12b486e05985b..d32933558d58671cef856637e09a3ac3563d70b6 100644 (file)
--- 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;