]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Fix some more bugs, and use dup2 because dup leaks on some implementations.
authorDale Weiler <killfieldengine@gmail.com>
Sat, 22 Jun 2013 01:14:13 +0000 (01:14 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sat, 22 Jun 2013 01:14:13 +0000 (01:14 +0000)
parser.c
test.c

index 6216997879e461e4c759cb17ec2959b9e362f5aa..49e965a097f0e5813023824e85062b38e3100da8 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2056,7 +2056,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
                         correct = correct_str(&corr, parser->correct_variables[i], parser_tokval(parser));
                         if (strcmp(correct, parser_tokval(parser))) {
                             break;
-                        } else if (correct) {
+                        } else  {
                             mem_d(correct);
                             correct = NULL;
                         }
@@ -2514,7 +2514,8 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond,
     }
 
     unary = (ast_unary*)cond;
-    while (ast_istype(cond, ast_unary) && unary->op == INSTR_NOT_F)
+    /* ast_istype dereferences cond, should test here for safety */
+    while (cond && ast_istype(cond, ast_unary) && unary->op == INSTR_NOT_F)
     {
         cond = unary->operand;
         unary->operand = NULL;
diff --git a/test.c b/test.c
index 5f7eac7c83e948b141d314f658d2005e66479486..cdb90415f4ed8532ae067b0ccb2a632206b33f59 100644 (file)
--- a/test.c
+++ b/test.c
@@ -104,6 +104,7 @@ static FILE ** task_popen(const char *command, const char *mode) {
         data->pipes  [0] = inhandle [1];
         data->pipes  [1] = outhandle[0];
         data->pipes  [2] = errhandle[0];
+
         data->handles[0] = fdopen(inhandle [1], "w");
         data->handles[1] = fdopen(outhandle[0], mode);
         data->handles[2] = fdopen(errhandle[0], mode);
@@ -119,9 +120,9 @@ static FILE ** task_popen(const char *command, const char *mode) {
         close(errhandle[0]);
 
         /* see piping documentation for this sillyness :P */
-        close(0); (void)!dup(inhandle [0]);
-        close(1); (void)!dup(outhandle[1]);
-        close(2); (void)!dup(errhandle[1]);
+        dup2(inhandle [0], 0);
+        dup2(outhandle[1], 1);
+        dup2(errhandle[1], 2);
 
         execvp(*argv, argv);
         exit(EXIT_FAILURE);
@@ -135,8 +136,7 @@ task_popen_error_2: close(outhandle[0]), close(outhandle[1]);
 task_popen_error_1: close(inhandle [0]), close(inhandle [1]);
 task_popen_error_0:
 
-    if (argv)
-        vec_free(argv);
+    vec_free(argv);
     return NULL;
 }
 
@@ -474,8 +474,7 @@ static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *f
     return true;
 
 failure:
-    if (back)
-        mem_d (back);
+    mem_d (back);
     return false;
 }