X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=util.c;h=65851631152aee7b285fd87a2496b6b201c3dd9e;hb=ad96056bdcf62abd585cdb53768fbabdde75d1b5;hp=3adfb264e958d177eaa818204e13fe12c419cac4;hpb=302189d124ed5849c2589ea92e912eb24fdc4ab3;p=debian%2Fgzip diff --git a/util.c b/util.c index 3adfb26..6585163 100644 --- a/util.c +++ b/util.c @@ -429,24 +429,23 @@ void fprint_off(file, offset, width) { char buf[CHAR_BIT * sizeof (off_t)]; char *p = buf + sizeof buf; - int negative = offset < 0; + /* Don't negate offset here; it might overflow. */ - do { - int remainder = offset % 10; - int quotient = offset / 10; - if (offset < 0 && 0 < remainder) { - remainder -= 10; - quotient++; - } - *--p = (remainder < 0 ? -remainder : remainder) + '0'; - width--; - offset = quotient; - } while (offset != 0); - for (width -= negative; 0 < width; width--) { - putc (' ', file); + if (offset < 0) { + do + *--p = '0' - offset % 10; + while ((offset /= 10) != 0); + + *--p = '-'; + } else { + do + *--p = '0' + offset % 10; + while ((offset /= 10) != 0); } - if (negative) { - putc ('-', file); + + width -= buf + sizeof buf - p; + while (0 < width--) { + putc (' ', file); } for (; p < buf + sizeof buf; p++) putc (*p, file);