ccanlint: fix more potential segvs when reporting ccanlint errors.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 24 Feb 2011 02:50:01 +0000 (13:20 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 24 Feb 2011 02:50:01 +0000 (13:20 +1030)
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
tools/ccanlint/compulsory_tests/module_builds.c
tools/ccanlint/tests/examples_run.c
tools/ccanlint/tests/headers_idempotent.c
tools/ccanlint/tests/info_summary_single_line.c
tools/ccanlint/tests/no_trailing_whitespace.c
tools/ccanlint/tests/tests_compile_coverage.c
tools/ccanlint/tests/tests_pass_valgrind.c

index 9d697a303a57399a1754da32db7dfc0c20d1ffa0..44c882ce357494fb1aadcb8331360c2b311da99c 100644 (file)
@@ -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;
        }
 
index 6418d833bfcd6126c786f37c4e5b28fbac5a70c3..4cf9242297988ad64b75835f098799aea52c2915 100644 (file)
@@ -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;
                        }
                }
index a1d30961f2035bc0dadbd9d557d9444f78f2edd5..7e0dc300c81307b6b7786c0306e964c94c8fbc86 100644 (file)
@@ -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;
        }
 
index b98ab74e729cfeeee0393550788b4168b78c64e9..4be98d43bf2f4d74bd36e908326f789ed517714b 100644 (file)
@@ -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]);
                }
        }
index 1018be3cd64938788a47019f71b11c832755fa8b..3f41877a31a42a4302fb1c8eb8ff44143450da67 100644 (file)
@@ -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);
                        }
                }
        }
index f41edc0bc6f36588a334a07c923707bbc10421d5..508057fa0d3b2d9ad61361211c01e92a94c48dc8 100644 (file)
@@ -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;
index da61dd364729daf87c42cbeb91fbe184e9069e0b..7ef0ac1aa9ac72809473befa118538580d820a1e 100644 (file)
@@ -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;
                        }
                }