From: Zbigniew Jędrzejewski-Szmek Date: Thu, 11 Feb 2021 08:50:49 +0000 (+0100) Subject: fsck: make sure we don't read an unitialized variable X-Git-Tag: v248-rc1~154^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=333ab199a12c7b060d3a3f4d50a8f73ee4fd5ebd;p=thirdparty%2Fsystemd.git fsck: make sure we don't read an unitialized variable This use on %n was completely unnecessary: fprintf returns the number of characters written. And the issue was that if fprintf failed for whatever reason, it would not process the %n and m would be unitialized. Rework the code a bit to simplify it. Coverity CID#1444708. --- diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index cd012f0f3ae..94aa31e71ac 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -172,7 +172,7 @@ static int process_progress(int fd, FILE* console) { } for (;;) { - int pass, m; + int pass; unsigned long cur, max; _cleanup_free_ char *device = NULL; double p; @@ -206,18 +206,17 @@ static int process_progress(int fd, FILE* console) { last = t; p = percent(pass, cur, max); - fprintf(console, "\r%s: fsck %3.1f%% complete...\r%n", device, p, &m); - fflush(console); + r = fprintf(console, "\r%s: fsck %3.1f%% complete...\r", device, p); + if (r < 0) + return -EIO; /* No point in continuing if something happend to our output stream */ - if (m > clear) - clear = m; + fflush(console); + clear = MAX(clear, r); } if (clear > 0) { - unsigned j; - fputc('\r', console); - for (j = 0; j < (unsigned) clear; j++) + for (int j = 0; j < clear; j++) fputc(' ', console); fputc('\r', console); fflush(console);