From f2773395289a058eb8b428c0a7e0832e004232c0 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Wed, 2 Dec 2020 13:32:48 -0600 Subject: [PATCH] add explicit casts to XMALLOC()s, even for (void *), to avoid warnings in C++ and MSVC/MSVS builds, and to avoid false positives on simple text searches. --- src/internal.c | 4 ++-- src/ssl.c | 4 ++-- src/wolfio.c | 2 +- wolfcrypt/src/asn.c | 2 +- wolfcrypt/src/chacha20_poly1305.c | 2 +- wolfcrypt/src/compress.c | 2 +- wolfcrypt/src/wc_pkcs11.c | 2 +- wolfcrypt/src/wc_port.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/internal.c b/src/internal.c index 2b245ea96..7a1da3686 100644 --- a/src/internal.c +++ b/src/internal.c @@ -351,7 +351,7 @@ static word32 GetEntropy(unsigned char* out, word32 num_bytes) static void* myAlloc(void* opaque, unsigned int item, unsigned int size) { (void)opaque; - return XMALLOC(item * size, opaque, DYNAMIC_TYPE_LIBZ); + return (void *)XMALLOC(item * size, opaque, DYNAMIC_TYPE_LIBZ); } @@ -6052,7 +6052,7 @@ int AllocKey(WOLFSSL* ssl, int type, void** pKey) } /* Allocate memory for key */ - *pKey = XMALLOC(sz, ssl->heap, type); + *pKey = (void *)XMALLOC(sz, ssl->heap, type); if (*pKey == NULL) { return MEMORY_E; } diff --git a/src/ssl.c b/src/ssl.c index 033a9955d..ece7f1870 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -29045,7 +29045,7 @@ void *wolfSSL_ASN1_item_new(const WOLFSSL_ASN1_ITEM *tpl) if (!tpl) { return NULL; } - if (!(ret = XMALLOC(tpl->size, NULL, DYNAMIC_TYPE_OPENSSL))) { + if (!(ret = (void *)XMALLOC(tpl->size, NULL, DYNAMIC_TYPE_OPENSSL))) { return NULL; } XMEMSET(ret, 0, tpl->size); @@ -31817,7 +31817,7 @@ void wolfSSL_OPENSSL_free(void* p) void *wolfSSL_OPENSSL_malloc(size_t a) { - return XMALLOC(a, NULL, DYNAMIC_TYPE_OPENSSL); + return (void *)XMALLOC(a, NULL, DYNAMIC_TYPE_OPENSSL); } int wolfSSL_OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) diff --git a/src/wolfio.c b/src/wolfio.c index bda4ce8ca..7a90ce7c8 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -2091,7 +2091,7 @@ void* mynewt_ctx_new() { if(!mynewt_ctx) return NULL; XMEMSET(mynewt_ctx, 0, sizeof(Mynewt_Ctx)); - mynewt_ctx->mnMemBuffer = XMALLOC(mempool_bytes, 0, 0); + mynewt_ctx->mnMemBuffer = (void *)XMALLOC(mempool_bytes, 0, 0); if(!mynewt_ctx->mnMemBuffer) { mynewt_ctx_clear((void*)mynewt_ctx); return NULL; diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 6c1d938d5..885b80159 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -1193,7 +1193,7 @@ int wc_BerToDer(const byte* ber, word32 berSz, byte* der, word32* derSz) return BAD_FUNC_ARG; #ifdef WOLFSSL_SMALL_STACK - indefItems = XMALLOC(sizeof(IndefItems), NULL, DYNAMIC_TYPE_TMP_BUFFER); + indefItems = (IndefItems *)XMALLOC(sizeof(IndefItems), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (indefItems == NULL) { ret = MEMORY_E; goto end; diff --git a/wolfcrypt/src/chacha20_poly1305.c b/wolfcrypt/src/chacha20_poly1305.c index 5d55b9208..86edc0b97 100644 --- a/wolfcrypt/src/chacha20_poly1305.c +++ b/wolfcrypt/src/chacha20_poly1305.c @@ -360,7 +360,7 @@ static WC_INLINE int wc_XChaCha20Poly1305_crypt_oneshot( byte *dst_i; size_t src_len_rem; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) - ChaChaPoly_Aead *aead = XMALLOC(sizeof *aead, NULL, DYNAMIC_TYPE_TMP_BUFFER); + ChaChaPoly_Aead *aead = (ChaChaPoly_Aead *)XMALLOC(sizeof *aead, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (aead == NULL) return MEMORY_E; diff --git a/wolfcrypt/src/compress.c b/wolfcrypt/src/compress.c index 5a91d851f..441750643 100644 --- a/wolfcrypt/src/compress.c +++ b/wolfcrypt/src/compress.c @@ -47,7 +47,7 @@ static void* myAlloc(void* opaque, unsigned int item, unsigned int size) { (void)opaque; - return XMALLOC(item * size, opaque, DYNAMIC_TYPE_LIBZ); + return (void *)XMALLOC(item * size, opaque, DYNAMIC_TYPE_LIBZ); } diff --git a/wolfcrypt/src/wc_pkcs11.c b/wolfcrypt/src/wc_pkcs11.c index c51c70522..a3778d3de 100644 --- a/wolfcrypt/src/wc_pkcs11.c +++ b/wolfcrypt/src/wc_pkcs11.c @@ -2476,7 +2476,7 @@ static int Pkcs11ECDSA_Verify(Pkcs11Session* session, wc_CryptoInfo* info) } if (ret == 0) { - sig = XMALLOC(sz * 2, info->pk.eccverify.key->heap, + sig = (unsigned char *)XMALLOC(sz * 2, info->pk.eccverify.key->heap, DYNAMIC_TYPE_TMP_BUFFER); if (sig == NULL) ret = MEMORY_E; diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 165bc4a70..ced1711e1 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -700,7 +700,7 @@ XFILE z_fs_open(const char* filename, const char* perm) { XFILE file; - file = XMALLOC(sizeof(*file), NULL, DYNAMIC_TYPE_FILE); + file = (XFILE)XMALLOC(sizeof(*file), NULL, DYNAMIC_TYPE_FILE); if (file != NULL) { if (fs_open(file, filename) != 0) { XFREE(file, NULL, DYNAMIC_TYPE_FILE);