X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=lib%2Fnum2str.c;h=896186888716424f13ecf0dc174a416cffeb7bd6;hb=1b10477b21157800f030c3ec91511a810e75e4c7;hp=a1041926c5e5aff50dc540227a89d9d76d17dfc6;hpb=22f80458a520d0c5371c64bf91d24cdd21dff825;p=fio.git diff --git a/lib/num2str.c b/lib/num2str.c index a1041926..89618688 100644 --- a/lib/num2str.c +++ b/lib/num2str.c @@ -2,6 +2,10 @@ #include #include +#include "../fio.h" + +#define ARRAY_LENGTH(arr) sizeof(arr) / sizeof((arr)[0]) + /* * Cheesy number->string conversion, complete with carry rounding error. */ @@ -44,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;