Skip to content

Commit

Permalink
fixup! replace various calls to sprintf() by BiO_snprintf() to avoid …
Browse files Browse the repository at this point in the history
…compiler warnings, e.g., on MacOS
  • Loading branch information
DDvO committed Oct 9, 2024
1 parent 36a46c9 commit 7645b1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions test/cmactest.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,13 @@ static int test_cmac_copy(void)
static char *pt(unsigned char *md, unsigned int len)
{
unsigned int i;
static char buf[80];
static char buf[81], *p = buf;
#define OSSL_HEX_CHARS_PER_BYTE 2

for (i = 0; i < len; i++)
BIO_snprintf(&(buf[i * 2]), sizeof(buf), "%02x", md[i]);
for (i = 0; i < len && p + OSSL_HEX_CHARS_PER_BYTE < buf + sizeof(buf); i++) {
BIO_snprintf(p, OSSL_HEX_CHARS_PER_BYTE + 1, "%02x", md[i]);
p += OSSL_HEX_CHARS_PER_BYTE;
}
return buf;
}

Expand Down
9 changes: 6 additions & 3 deletions test/hmactest.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,15 @@ static int test_hmac_copy_uninited(void)
static char *pt(unsigned char *md, unsigned int len)
{
unsigned int i;
static char buf[200];
static char buf[201], *p = buf;
#define OSSL_HEX_CHARS_PER_BYTE 2

if (md == NULL)
return NULL;
for (i = 0; i < len; i++)
BIO_snprintf(&(buf[i * 2]), sizeof(buf), "%02x", md[i]);
for (i = 0; i < len && p + OSSL_HEX_CHARS_PER_BYTE < buf + sizeof(buf); i++) {
BIO_snprintf(p, OSSL_HEX_CHARS_PER_BYTE + 1, "%02x", md[i]);
p += OSSL_HEX_CHARS_PER_BYTE;
}
return buf;
}
# endif
Expand Down

0 comments on commit 7645b1d

Please sign in to comment.