From 4a5dea3435cc6b1e2322240124f18948240cf4b2 Mon Sep 17 00:00:00 2001 From: Mike Massonnet Date: Sat, 15 Nov 2014 23:00:15 +0100 Subject: [PATCH] Fix unit_names index --- panel-plugin/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/panel-plugin/utils.c b/panel-plugin/utils.c index c49744a..c2824ba 100644 --- a/panel-plugin/utils.c +++ b/panel-plugin/utils.c @@ -76,7 +76,7 @@ char* format_byte_humanreadable(char* string, int stringsize, double number, int char buffer[BUFSIZ], formatstring[BUFSIZ]; char* bufptr = buffer; char* unit_names[] = { N_("B"), N_("KiB"), N_("MiB"), N_("GiB") }; - unsigned int uidx = 1; + unsigned int uidx = 0; double number_displayed = number / 1024.0; unsigned int i; int numberOfIntegerChars, count; @@ -97,7 +97,7 @@ char* format_byte_humanreadable(char* string, int stringsize, double number, int } /* calculate number and appropriate unit size for display */ - while(number_displayed >= 1024.0 && uidx < sizeof(unit_names)) + while(number_displayed >= 1024.0 && uidx < (sizeof(unit_names) / sizeof(char*) - 1)) { number_displayed /= 1024.0; uidx++;