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 ca43b3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions test/cmactest.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,15 @@ 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];

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

Expand Down
12 changes: 7 additions & 5 deletions test/hmactest.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,21 @@ static int test_hmac_copy_uninited(void)
return res;
}

# ifndef OPENSSL_NO_MD5
#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];

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 && (i + 1) * OSSL_HEX_CHARS_PER_BYTE < sizeof(buf); i++)
BIO_snprintf(buf + i * OSSL_HEX_CHARS_PER_BYTE,
OSSL_HEX_CHARS_PER_BYTE + 1, "%02x", md[i]);
return buf;
}
# endif
#endif

static struct test_chunks_st {
const char *md_name;
Expand Down

0 comments on commit ca43b3c

Please sign in to comment.