Skip to content

Commit 6a91414

Browse files
committed
ctlib: Reduce possible reentrance issues for res_type_str
Change output buffer instead of always use the same one. Not solving all possible issues but fine for test code. Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
1 parent 9a13fcc commit 6a91414

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ctlib/unittests/common.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ servermsg_cb(CS_CONTEXT * context TDS_UNUSED, CS_CONNECTION * connection TDS_UNU
384384
const char *
385385
res_type_str(CS_RETCODE ret)
386386
{
387-
static char str[64];
387+
static char str[4][32];
388+
static uint8_t last_used;
389+
uint8_t n;
388390

389391
#define S(s) case s: return #s;
390392
switch ((int) ret) {
@@ -399,8 +401,9 @@ res_type_str(CS_RETCODE ret)
399401
#undef S
400402
}
401403

402-
sprintf(str, "?? (%d)", (int) ret);
403-
return str;
404+
n = (last_used++) & 3;
405+
snprintf(str[n], sizeof(str[0]), "?? (%d)", (int) ret);
406+
return str[n];
404407
}
405408

406409
void

0 commit comments

Comments
 (0)