Browse Source

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
Rusty Russell 15 years ago
parent
commit
299dc8f99c

+ 1 - 1
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;
 	}
 

+ 5 - 9
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;
 			}
 		}

+ 6 - 8
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;
 	}
 

+ 2 - 2
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]);
 		}
 	}

+ 2 - 1
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);
 			}
 		}
 	}

+ 1 - 1
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;

+ 3 - 2
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;
 			}
 		}