]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.cpp
fix some UB
[xonotic/gmqcc.git] / parser.cpp
index 63e49d056969f4b3360f697050722c67241f34a9..9bfd7517a26aea26b9671f362f6e9be58dcdfd50 100644 (file)
@@ -135,17 +135,22 @@ static ast_expression* parser_find_local(parser_t *parser, const char *name, siz
 {
     size_t          i, hash;
     ast_expression *e;
+    ast_expression *p;
 
     hash = util_hthash(parser->htglobals, name);
 
     *isparam = false;
+    p = parser_find_param(parser, name);
+    if (p) {
+        *isparam = true;
+        return p;
+    }
     for (i = parser->variables.size(); i > upto;) {
         --i;
         if ( (e = (ast_expression*)util_htgeth(parser->variables[i], name, hash)) )
             return e;
     }
-    *isparam = true;
-    return parser_find_param(parser, name);
+    return NULL;
 }
 
 static ast_expression* parser_find_local(parser_t *parser, const std::string &name, size_t upto, bool *isparam) {
@@ -342,7 +347,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
     const oper_info *op;
     lex_ctx_t ctx;
     ast_expression *out = nullptr;
-    ast_expression *exprs[3];
+    ast_expression *exprs[3] = { 0, 0, 0 };
     ast_block      *blocks[3];
     ast_binstore   *asbinstore;
     size_t i, assignop, addop, subop;
@@ -3163,6 +3168,7 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression *
             }
             if (!OPTS_FLAG(RELAXED_SWITCH)) {
                 if (!ast_istype(swcase.m_value, ast_value)) { /* || ((ast_value*)swcase.m_value)->m_cvq != CV_CONST) { */
+                    delete switchnode;
                     parseerror(parser, "case on non-constant values need to be explicitly enabled via -frelaxed-switch");
                     ast_unref(operand);
                     return false;