From dee9766d56606cdf58ccc4577c2ed610ef9699e8 Mon Sep 17 00:00:00 2001 From: Mikhail Litsarev Date: Thu, 11 Jun 2026 17:52:25 +0300 Subject: [PATCH v1] =?UTF-8?q?Fix=20warning:=20=E2=80=98startpos=E2=80=99?= =?UTF-8?q?=20may=20be=20used=20uninitialized=20in=20function=20=E2=80=98r?= =?UTF-8?q?esults=5Fdiffer=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/regress/pg_regress.c | 79 +++++++++++++++++------------------ 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index 1c052cc0fbf..155172aebcb 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -1556,56 +1556,55 @@ results_differ(const char *testname, const char *resultsfile, const char *defaul * Windows the file lock prevents diff from writing. */ difffile = fopen(difffilename, "r"); - } + if (difffile) + { + /* + * In case of a crash the diff can be huge and all of the subsequent + * tests will fail with essentially useless diffs too. So to avoid + * flooding the output, while still providing useful info in most + * cases we output only the first 80 lines of the *combined* diff. The + * number 80 is chosen so that we output less than 100 lines of + * diagnostics per pg_regress run. Otherwise if meson is run with the + * --quiet flag only the last 100 lines are shown and usually the most + * useful information is actually in the first few lines. + */ + static int nlines = 0; + const int max_diff_lines = 80; + char line[1024]; - if (difffile) - { - /* - * In case of a crash the diff can be huge and all of the subsequent - * tests will fail with essentially useless diffs too. So to avoid - * flooding the output, while still providing useful info in most - * cases we output only the first 80 lines of the *combined* diff. The - * number 80 is chosen so that we output less than 100 lines of - * diagnostics per pg_regress run. Otherwise if meson is run with the - * --quiet flag only the last 100 lines are shown and usually the most - * useful information is actually in the first few lines. - */ - static int nlines = 0; - const int max_diff_lines = 80; - char line[1024]; + fseek(difffile, startpos, SEEK_SET); + while (nlines < max_diff_lines && + fgets(line, sizeof(line), difffile)) + { + size_t len = strlen(line); + bool newline_found = (len > 0 && line[len - 1] == '\n'); - fseek(difffile, startpos, SEEK_SET); - while (nlines < max_diff_lines && - fgets(line, sizeof(line), difffile)) - { - size_t len = strlen(line); - bool newline_found = (len > 0 && line[len - 1] == '\n'); + if (newline_found) + line[len - 1] = '\0'; - if (newline_found) - line[len - 1] = '\0'; + diag_detail("%s", line); + if (newline_found) + { + diag_end(); + nlines++; + } + } - diag_detail("%s", line); - if (newline_found) + if (in_diag) { + /* + * If there was no final newline for some reason, we should still + * end the diagnostic. + */ diag_end(); nlines++; } - } - if (in_diag) - { - /* - * If there was no final newline for some reason, we should still - * end the diagnostic. - */ - diag_end(); - nlines++; - } - - if (nlines >= max_diff_lines) - diag("(diff output truncated and silencing output for further failing tests...)"); + if (nlines >= max_diff_lines) + diag("(diff output truncated and silencing output for further failing tests...)"); - fclose(difffile); + fclose(difffile); + } } unlink(diff); -- 2.34.1