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 7da1b41 commit 370f10f
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 @@ -327,13 +327,16 @@ static int test_cmac_copy(void)
return ret;
}

#define OSSL_HEX_CHARS_PER_BYTE 2
static char *pt(unsigned char *md, unsigned int len)
{
unsigned int i;
static char buf[80];
static char buf[81], *p = buf;

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 @@ -276,15 +276,18 @@ static int test_hmac_copy_uninited(void)
}

# ifndef OPENSSL_NO_MD5
# define OSSL_HEX_CHARS_PER_BYTE 2
static char *pt(unsigned char *md, unsigned int len)
{
unsigned int i;
static char buf[200];
static char buf[201], *p = buf;

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 370f10f

Please sign in to comment.