X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=lib%2Fnum2str.c;h=896186888716424f13ecf0dc174a416cffeb7bd6;hp=12d6f39aa5dbca892e9d03af9150aa28a3a47861;hb=652ae149194f753b5f074b4c5984acc76ebb24f1;hpb=c0c4b1d42e39c2ea4cb2d58e5a17aec4b00263d9 diff --git a/lib/num2str.c b/lib/num2str.c index 12d6f39a..89618688 100644 --- a/lib/num2str.c +++ b/lib/num2str.c @@ -4,6 +4,8 @@ #include "../fio.h" +#define ARRAY_LENGTH(arr) sizeof(arr) / sizeof((arr)[0]) + /* * Cheesy number->string conversion, complete with carry rounding error. */ @@ -46,6 +48,9 @@ char *num2str(unsigned long num, int maxlen, int base, int pow2, int unit_base) if (modulo == -1U) { done: + if (post_index >= ARRAY_LENGTH(postfix)) + post_index = 0; + sprintf(buf, "%lu%s%s", num, postfix[post_index], byte_postfix[byte_post_index]); return buf;