Fix unit_names index

master
Mike Massonnet 2014-11-15 23:00:15 +01:00
parent d6d8e31dac
commit 4a5dea3435
1 changed files with 2 additions and 2 deletions

View File

@ -76,7 +76,7 @@ char* format_byte_humanreadable(char* string, int stringsize, double number, int
char buffer[BUFSIZ], formatstring[BUFSIZ]; char buffer[BUFSIZ], formatstring[BUFSIZ];
char* bufptr = buffer; char* bufptr = buffer;
char* unit_names[] = { N_("B"), N_("KiB"), N_("MiB"), N_("GiB") }; 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; double number_displayed = number / 1024.0;
unsigned int i; unsigned int i;
int numberOfIntegerChars, count; 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 */ /* 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; number_displayed /= 1024.0;
uidx++; uidx++;