cleanups and fixes that cppcheck found

This commit is contained in:
Dale Weiler 2012-12-22 08:07:54 +00:00
parent 322fbaf389
commit 7d2a2f2ade
3 changed files with 16 additions and 3 deletions

3
exec.c
View file

@ -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);

View file

@ -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");

10
test.c
View file

@ -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));