From 5506925b346b09f8556ce2c8f83fe3d69dc1c03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 8 Dec 2020 16:36:00 +0100 Subject: [PATCH] Use sizeof buffer instead of magic number --- MemoryMeter.c | 8 ++++---- SwapMeter.c | 4 ++-- zfs/ZfsArcMeter.c | 14 +++++++------- zfs/ZfsCompressedArcMeter.c | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/MemoryMeter.c b/MemoryMeter.c index 9830bf51..ad846527 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -35,15 +35,15 @@ static void MemoryMeter_display(const Object* cast, RichString* out) { char buffer[50]; const Meter* this = (const Meter*)cast; RichString_write(out, CRT_colors[METER_TEXT], ":"); - Meter_humanUnit(buffer, this->total, 50); + Meter_humanUnit(buffer, this->total, sizeof(buffer)); RichString_append(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[0], 50); + Meter_humanUnit(buffer, this->values[0], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " used:"); RichString_append(out, CRT_colors[MEMORY_USED], buffer); - Meter_humanUnit(buffer, this->values[1], 50); + Meter_humanUnit(buffer, this->values[1], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " buffers:"); RichString_append(out, CRT_colors[MEMORY_BUFFERS_TEXT], buffer); - Meter_humanUnit(buffer, this->values[2], 50); + Meter_humanUnit(buffer, this->values[2], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " cache:"); RichString_append(out, CRT_colors[MEMORY_CACHE], buffer); } diff --git a/SwapMeter.c b/SwapMeter.c index 8e39c752..fcc11c54 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -33,9 +33,9 @@ static void SwapMeter_display(const Object* cast, RichString* out) { char buffer[50]; const Meter* this = (const Meter*)cast; RichString_write(out, CRT_colors[METER_TEXT], ":"); - Meter_humanUnit(buffer, this->total, 50); + Meter_humanUnit(buffer, this->total, sizeof(buffer)); RichString_append(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[0], 50); + Meter_humanUnit(buffer, this->values[0], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " used:"); RichString_append(out, CRT_colors[METER_VALUE], buffer); } diff --git a/zfs/ZfsArcMeter.c b/zfs/ZfsArcMeter.c index e844d779..ddc239e3 100644 --- a/zfs/ZfsArcMeter.c +++ b/zfs/ZfsArcMeter.c @@ -50,24 +50,24 @@ static void ZfsArcMeter_display(const Object* cast, RichString* out) { if (this->values[5] > 0) { char buffer[50]; - Meter_humanUnit(buffer, this->total, 50); + Meter_humanUnit(buffer, this->total, sizeof(buffer)); RichString_append(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[5], 50); + Meter_humanUnit(buffer, this->values[5], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " Used:"); RichString_append(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[0], 50); + Meter_humanUnit(buffer, this->values[0], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " MFU:"); RichString_append(out, CRT_colors[ZFS_MFU], buffer); - Meter_humanUnit(buffer, this->values[1], 50); + Meter_humanUnit(buffer, this->values[1], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " MRU:"); RichString_append(out, CRT_colors[ZFS_MRU], buffer); - Meter_humanUnit(buffer, this->values[2], 50); + Meter_humanUnit(buffer, this->values[2], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " Anon:"); RichString_append(out, CRT_colors[ZFS_ANON], buffer); - Meter_humanUnit(buffer, this->values[3], 50); + Meter_humanUnit(buffer, this->values[3], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " Hdr:"); RichString_append(out, CRT_colors[ZFS_HEADER], buffer); - Meter_humanUnit(buffer, this->values[4], 50); + Meter_humanUnit(buffer, this->values[4], sizeof(buffer)); RichString_append(out, CRT_colors[METER_TEXT], " Oth:"); RichString_append(out, CRT_colors[ZFS_OTHER], buffer); } else { diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index 8766f801..224c6144 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -47,13 +47,13 @@ static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) { if (this->values[0] > 0) { char buffer[50]; - Meter_humanUnit(buffer, this->total, 50); + Meter_humanUnit(buffer, this->total, sizeof(buffer)); RichString_append(out, CRT_colors[METER_VALUE], buffer); RichString_append(out, CRT_colors[METER_TEXT], " Uncompressed, "); - Meter_humanUnit(buffer, this->values[0], 50); + Meter_humanUnit(buffer, this->values[0], sizeof(buffer)); RichString_append(out, CRT_colors[METER_VALUE], buffer); RichString_append(out, CRT_colors[METER_TEXT], " Compressed, "); - ZfsCompressedArcMeter_printRatioString(this, buffer, 50); + ZfsCompressedArcMeter_printRatioString(this, buffer, sizeof(buffer)); RichString_append(out, CRT_colors[METER_VALUE], buffer); RichString_append(out, CRT_colors[METER_TEXT], " Ratio"); } else {