diff --git a/ut.c b/ut.c index 9179f6658e7..6bd60fbaeb8 100644 --- a/ut.c +++ b/ut.c @@ -30,6 +30,7 @@ #include #include "ut.h" +unsigned int int2str_buf_index = 0; char int2str_buf[INT2STR_BUF_NO][INT2STR_MAX_LEN]; int tcp_timeout_con_get = 0; diff --git a/ut.h b/ut.h index 60ca58160ae..4323b884855 100644 --- a/ut.h +++ b/ut.h @@ -271,13 +271,15 @@ static inline char* int2bstr(uint64_t l, char *s, int* len) /* INTeger-TO-STRing : convers a 64-bit integer to a string * returns a pointer to a static buffer containing l in asciiz & sets len */ #define INT2STR_BUF_NO 7 +extern unsigned int int2str_buf_index; extern char int2str_buf[INT2STR_BUF_NO][INT2STR_MAX_LEN]; +static inline unsigned int getstrbufindex() { + return ((int2str_buf_index++) % INT2STR_BUF_NO); +} + static inline char* int2str(uint64_t l, int* len) { - static unsigned int it = 0; - - if ((++it)==INT2STR_BUF_NO) it = 0; - return int2bstr( l, int2str_buf[it], len); + return int2bstr( l, int2str_buf[getstrbufindex()], len); } @@ -303,9 +305,9 @@ static inline char* sint2str(long l, int* len) static inline char* double2str(double d, int* len) { - static int buf; + unsigned int buf; - buf = (buf + 1) % INT2STR_BUF_NO; + buf = getstrbufindex(); *len = snprintf(int2str_buf[buf], INT2STR_MAX_LEN - 1, "%0.*lf", FLOATING_POINT_PRECISION, d); int2str_buf[buf][*len] = '\0';