From: Rusty Russell Date: Thu, 24 Feb 2011 02:50:01 +0000 (+1030) Subject: ccanlint: fix more potential segvs when reporting ccanlint errors. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=299dc8f99ca642943db4f0204b5fe31065545d27 ccanlint: fix more potential segvs when reporting ccanlint errors. When I changed score_file_error() to printf-style, I didn't audit all the callers who were handing string literals. I've finally done that; I should have broken the compile by renaming it. Rusty fails refactoring 101. Reported-by: Andreas Schlick --- diff --git a/tools/ccanlint/compulsory_tests/module_builds.c b/tools/ccanlint/compulsory_tests/module_builds.c index 9d697a30..44c882ce 100644 --- a/tools/ccanlint/compulsory_tests/module_builds.c +++ b/tools/ccanlint/compulsory_tests/module_builds.c @@ -65,7 +65,7 @@ static void do_build(struct manifest *m, m->compiled = build_module(m, keep, &errstr); if (!m->compiled) { - score_file_error(score, NULL, 0, errstr); + score_file_error(score, NULL, 0, "%s", errstr); return; } diff --git a/tools/ccanlint/tests/examples_run.c b/tools/ccanlint/tests/examples_run.c index 6418d833..4cf92422 100644 --- a/tools/ccanlint/tests/examples_run.c +++ b/tools/ccanlint/tests/examples_run.c @@ -247,7 +247,6 @@ static void run_examples(struct manifest *m, bool keep, linenum++, expect = find_expect(i, lines, &input, &exact, &linenum)) { - char *err; if (i->compiled == NULL) continue; @@ -257,14 +256,11 @@ static void run_examples(struct manifest *m, bool keep, score->score++; continue; } - err = talloc_asprintf(score, - "output '%s' didn't" - " %s '%s'\n", - output, - exact - ? "match" : "contain", - expect); - score_file_error(score, i, linenum+1, err); + score_file_error(score, i, linenum+1, + "output '%s' didn't %s '%s'\n", + output, + exact ? "match" : "contain", + expect); score->pass = false; } } diff --git a/tools/ccanlint/tests/headers_idempotent.c b/tools/ccanlint/tests/headers_idempotent.c index a1d30961..7e0dc300 100644 --- a/tools/ccanlint/tests/headers_idempotent.c +++ b/tools/ccanlint/tests/headers_idempotent.c @@ -145,18 +145,16 @@ static void check_idem(struct ccan_file *f, struct score *score) if (!get_token(&line, "#")) abort(); if (!get_token(&line, "define")) { - char *str = talloc_asprintf(score, - "expected '#define %s'", - line_info[i].cond->symbol); - score_file_error(score, f, i+1, str); + score_file_error(score, f, i+1, + "expected '#define %s'", + line_info[i].cond->symbol); return; } sym = get_symbol_token(f, &line); if (!sym || !streq(sym, line_info[i].cond->symbol)) { - char *str = talloc_asprintf(score, - "expected '#define %s'", - line_info[i].cond->symbol); - score_file_error(score, f, i+1, str); + score_file_error(score, f, i+1, + "expected '#define %s'", + line_info[i].cond->symbol); return; } diff --git a/tools/ccanlint/tests/info_summary_single_line.c b/tools/ccanlint/tests/info_summary_single_line.c index b98ab74e..4be98d43 100644 --- a/tools/ccanlint/tests/info_summary_single_line.c +++ b/tools/ccanlint/tests/info_summary_single_line.c @@ -27,8 +27,8 @@ static void check_info_summary_single_line(struct manifest *m, score->pass = false; score->score = 0; score_file_error(score, m->info_file, d->srcline+1, - m->info_file->lines[d->srcline]); - score_file_error(score, m->info_file, d->srcline+2, + "%s\n%s", + m->info_file->lines[d->srcline], m->info_file->lines[d->srcline+1]); } } diff --git a/tools/ccanlint/tests/no_trailing_whitespace.c b/tools/ccanlint/tests/no_trailing_whitespace.c index 1018be3c..3f41877a 100644 --- a/tools/ccanlint/tests/no_trailing_whitespace.c +++ b/tools/ccanlint/tests/no_trailing_whitespace.c @@ -36,7 +36,8 @@ static void check_trailing_whitespace(struct manifest *m, for (i = 0; i < f->num_lines; i++) { char *err = get_trailing_whitespace(lines[i]); if (err) - score_file_error(score, f, i+1, err); + score_file_error(score, f, i+1, + "%s", err); } } } diff --git a/tools/ccanlint/tests/tests_compile_coverage.c b/tools/ccanlint/tests/tests_compile_coverage.c index f41edc0b..508057fa 100644 --- a/tools/ccanlint/tests/tests_compile_coverage.c +++ b/tools/ccanlint/tests/tests_compile_coverage.c @@ -40,7 +40,7 @@ static bool build_module_objs_with_coverage(struct manifest *m, bool keep, i->cov_compiled = maybe_temp_file(m, "", keep, fullfile); if (!compile_object(m, fullfile, ccan_dir, "", i->cov_compiled, &err)) { - score_file_error(score, i, 0, err); + score_file_error(score, i, 0, "%s", err); talloc_free(i->cov_compiled); i->cov_compiled = NULL; return false; diff --git a/tools/ccanlint/tests/tests_pass_valgrind.c b/tools/ccanlint/tests/tests_pass_valgrind.c index da61dd36..7ef0ac1a 100644 --- a/tools/ccanlint/tests/tests_pass_valgrind.c +++ b/tools/ccanlint/tests/tests_pass_valgrind.c @@ -127,7 +127,7 @@ static void do_run_tests_vg(struct manifest *m, i->leak_info = get_leaks(output, &err); } if (err) - score_file_error(score, i, 0, err); + score_file_error(score, i, 0, "%s", err); else score->score++; } @@ -149,7 +149,8 @@ static void do_leakcheck_vg(struct manifest *m, foreach_ptr(list, &m->run_tests, &m->api_tests) { list_for_each(list, i, list) { if (i->leak_info) { - score_file_error(score, i, 0, i->leak_info); + score_file_error(score, i, 0, "%s", + i->leak_info); leaks = true; } }