Skip to content

Commit

Permalink
xz: Avoid a compiler warning in progress_speed() in message.c.
Browse files Browse the repository at this point in the history
This should be smaller too since it avoids the string constants.
  • Loading branch information
JiaT75 authored and Larhzu committed Nov 7, 2022
1 parent cf118c0 commit 1fc6e7d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/xz/message.c
Expand Up @@ -355,11 +355,8 @@ progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
if (elapsed < 3000)
return "";

static const char unit[][8] = {
"KiB/s",
"MiB/s",
"GiB/s",
};
// The first character of KiB/s, MiB/s, or GiB/s:
static const char unit[] = { 'K', 'M', 'G' };

size_t unit_index = 0;

Expand All @@ -381,7 +378,7 @@ progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
// - 999 KiB/s
// Use big enough buffer to hold e.g. a multibyte decimal point.
static char buf[16];
snprintf(buf, sizeof(buf), "%.*f %s",
snprintf(buf, sizeof(buf), "%.*f %ciB/s",
speed > 9.9 ? 0 : 1, speed, unit[unit_index]);
return buf;
}
Expand Down

0 comments on commit 1fc6e7d

Please sign in to comment.