From 7d2a2f2ade517b430542516f7be099fe8e230cf1 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Sat, 22 Dec 2012 08:07:54 +0000 Subject: [PATCH] cleanups and fixes that cppcheck found --- exec.c | 3 ++- parser.c | 6 ++++++ test.c | 10 ++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/exec.c b/exec.c index 6e51c02..aaaa88b 100644 --- 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); diff --git a/parser.c b/parser.c index 128fa4f..9955058 100644 --- 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 0559e61..1a12f07 100644 --- 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)); -- 2.39.2