Skip to content

Commit

Permalink
Merge pull request #3308 from ovidiusas/master
Browse files Browse the repository at this point in the history
core: consistent usage of int2str_buf
(cherry picked from commit 358afd0)
  • Loading branch information
bogdan-iancu committed Feb 22, 2024
1 parent 3bf207f commit d2e2a69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <grp.h>
#include "ut.h"

unsigned int int2str_buf_index = 0;
char int2str_buf[INT2STR_BUF_NO][INT2STR_MAX_LEN];

int tcp_timeout_con_get = 0;
Expand Down
14 changes: 8 additions & 6 deletions ut.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,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(void) {
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);
}


Expand All @@ -291,9 +293,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';
Expand Down

0 comments on commit d2e2a69

Please sign in to comment.