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.
}
for (;;) {
- int pass, m;
+ int pass;
unsigned long cur, max;
_cleanup_free_ char *device = NULL;
double p;
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);