]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2image: eliminate division by zero
authorTheodore Ts'o <tytso@mit.edu>
Fri, 3 Jan 2014 02:04:01 +0000 (21:04 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 5 Jan 2014 00:11:37 +0000 (19:11 -0500)
Dividing a floating point number by zero is undefined in C.  It
happens to work with gcc/glibc, but it's not something that's
guaranteed.

Addresses-Coverity-ID: #1147781

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
misc/e2image.c

index 253fad1d011cb50b14fd399ae00b54ff81ec6f90..ac62ffec7165b8da06b88a4d48e3bc24d86e6b74 100644 (file)
@@ -704,14 +704,15 @@ more_blocks:
        if (show_progress) {
                time_t duration = time(NULL) - start_time;
                char buff[30];
-               while (bscount--)
-                       fputc('\b', stderr);
+               fputc('\r', stderr);
                strftime(buff, 30, "%T", gmtime(&duration));
-               fprintf(stderr, _("\b\b\b\b\b\b\b\bCopied %llu / %llu "
-                        "blocks (%d%%) in %s at %.2f MB/s       \n"),
-                      total_written, meta_blocks_count,
-                      calc_percent(total_written, meta_blocks_count), buff,
-                      calc_rate(total_written, fs->blocksize, duration));
+               fprintf(stderr, _("Copied %llu / %llu blocks (%d%%) in %s "),
+                       total_written, meta_blocks_count,
+                       calc_percent(total_written, meta_blocks_count), buff);
+               if (duration)
+                       fprintf(stderr, _("at %.2f MB/s"),
+                               calc_rate(total_written, fs->blocksize, duration));
+               fputs("       \n", stderr);
        }
 #ifdef HAVE_FTRUNCATE64
        if (sparse) {