]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
cleanups and fixes that cppcheck found
authorDale Weiler <killfieldengine@gmail.com>
Sat, 22 Dec 2012 08:07:54 +0000 (08:07 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sat, 22 Dec 2012 08:07:54 +0000 (08:07 +0000)
exec.c
parser.c
test.c

diff --git a/exec.c b/exec.c
index 6e51c027930a8a44c7dd360fd1443b029473b8c9..aaaa88b3b830fe9737c9fe7433ec36f9a186a3e4 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -644,7 +644,8 @@ static int qc_print(qc_program *prog)
     const char *laststr = NULL;
     for (i = 0; i < (size_t)prog->argc; ++i) {
         qcany *str = (qcany*)(prog->globals + OFS_PARM0 + 3*i);
-        printf("%s", (laststr = prog_getstring(prog, str->string)));
+        laststr = prog_getstring(prog, str->string);
+        printf("%s", laststr);
     }
     if (laststr && (prog->xflags & VMXF_TRACE)) {
         size_t len = strlen(laststr);
index 128fa4f79c2d2210f47a1e88eb5fb95b2be97788..9955058360ad5d842fa91757e85955f5327a9c93 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1921,6 +1921,12 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond,
             /* use the right NOT_ */
             prev = cond;
             cond = (ast_expression*)ast_unary_new(ast_ctx(cond), type_not_instr[cond->expression.vtype], cond);
+
+            /*
+             * cppcheck: it thinks there is a possible null pointer dereference
+             * otherwise it would be "redundant" to check it ast_unary_new returned
+             * null, it's wrong.
+             */   
             if (!cond) {
                 ast_unref(prev);
                 parseerror(parser, "internal error: failed to process condition");
diff --git a/test.c b/test.c
index 0559e618c3f64b4b0f1f371a85b06a74f5ba4e03..1a12f078043a7070b3c1b281a910e11acd0270b6 100644 (file)
--- a/test.c
+++ b/test.c
@@ -414,7 +414,10 @@ bool task_template_generate(task_template_t *template, char tag, const char *fil
      * Value will contain a newline character at the end, we need to strip
      * this otherwise kaboom, seriously, kaboom :P
      */
-    *strrchr(value, '\n')='\0';
+    if (strchr(value, '\n'))
+        *strrchr(value, '\n')='\0';
+    else /* cppcheck: possible nullpointer dereference */
+        abort();
 
     /*
      * Now allocate and set the actual value for the specific tag. Which
@@ -515,7 +518,10 @@ bool task_template_parse(const char *file, task_template_t *template, FILE *fp)
                  * Value will contain a newline character at the end, we need to strip
                  * this otherwise kaboom, seriously, kaboom :P
                  */
-                *strrchr(value, '\n')='\0';
+                if (strrchr(value, '\n'))
+                    *strrchr(value, '\n')='\0';
+                else /* cppcheck: possible null pointer dereference */
+                    abort();
 
                 vec_push(template->comparematch, util_strdup(value));