Add bloom filter
[fio.git] / lib / num2str.c
index a1041926c5e5aff50dc540227a89d9d76d17dfc6..896186888716424f13ecf0dc174a416cffeb7bd6 100644 (file)
@@ -2,6 +2,10 @@
 #include <stdio.h>
 #include <string.h>
 
+#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;