diff --git a/tests/api.c b/tests/api.c index f9e14d433..f2bf53726 100644 --- a/tests/api.c +++ b/tests/api.c @@ -396,6 +396,16 @@ typedef struct testVector { static const char* passed = "passed"; static const char* failed = "failed"; +#define TEST_STRING "Everyone gets Friday off." +#define TEST_STRING_SZ 25 + +#if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) +#define TEST_RSA_BITS 1024 +#else +#define TEST_RSA_BITS 2048 +#endif +#define TEST_RSA_BYTES (TEST_RSA_BITS/8) + #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \ (!defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT)) static const char* bogusFile = @@ -2312,8 +2322,8 @@ static void test_ED25519(void) unsigned int privSz = (unsigned int)sizeof(priv); byte pub[ED25519_PUB_KEY_SIZE]; unsigned int pubSz = (unsigned int)sizeof(pub); - const char* msg = "Everyone gets Friday off."; - unsigned int msglen = (unsigned int)XSTRLEN(msg); + const char* msg = TEST_STRING; + unsigned int msglen = (unsigned int)TEST_STRING_SZ; byte sig[ED25519_SIG_SIZE]; unsigned int sigSz = (unsigned int)sizeof(sig); @@ -2338,8 +2348,8 @@ static void test_ED448(void) unsigned int privSz = (unsigned int)sizeof(priv); byte pub[ED448_PUB_KEY_SIZE]; unsigned int pubSz = (unsigned int)sizeof(pub); - const char* msg = "Everyone gets Friday off."; - unsigned int msglen = (unsigned int)XSTRLEN(msg); + const char* msg = TEST_STRING; + unsigned int msglen = (unsigned int)TEST_STRING_SZ; byte sig[ED448_SIG_SIZE]; unsigned int sigSz = (unsigned int)sizeof(sig); @@ -9228,8 +9238,8 @@ static int test_wc_Sha3_224_Copy (void) int ret = 0; #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224) wc_Sha3 sha3, sha3Cpy; - const char* msg = "Everyone gets Friday off."; - word32 msglen = (word32)XSTRLEN(msg); + const char* msg = TEST_STRING; + word32 msglen = (word32)TEST_STRING_SZ; byte hash[WC_SHA3_224_DIGEST_SIZE]; byte hashCpy[WC_SHA3_224_DIGEST_SIZE]; @@ -9293,8 +9303,8 @@ static int test_wc_Sha3_256_Copy (void) int ret = 0; #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256) wc_Sha3 sha3, sha3Cpy; - const char* msg = "Everyone gets Friday off."; - word32 msglen = (word32)XSTRLEN(msg); + const char* msg = TEST_STRING; + word32 msglen = (word32)TEST_STRING_SZ; byte hash[WC_SHA3_256_DIGEST_SIZE]; byte hashCpy[WC_SHA3_256_DIGEST_SIZE]; @@ -9358,8 +9368,8 @@ static int test_wc_Sha3_384_Copy (void) int ret = 0; #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384) wc_Sha3 sha3, sha3Cpy; - const char* msg = "Everyone gets Friday off."; - word32 msglen = (word32)XSTRLEN(msg); + const char* msg = TEST_STRING; + word32 msglen = (word32)TEST_STRING_SZ; byte hash[WC_SHA3_384_DIGEST_SIZE]; byte hashCpy[WC_SHA3_384_DIGEST_SIZE]; @@ -9423,8 +9433,8 @@ static int test_wc_Sha3_512_Copy (void) #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) wc_Sha3 sha3, sha3Cpy; - const char* msg = "Everyone gets Friday off."; - word32 msglen = (word32)XSTRLEN(msg); + const char* msg = TEST_STRING; + word32 msglen = (word32)TEST_STRING_SZ; byte hash[WC_SHA3_512_DIGEST_SIZE]; byte hashCpy[WC_SHA3_512_DIGEST_SIZE]; @@ -9665,8 +9675,8 @@ static int test_wc_Shake256_Copy (void) int ret = 0; #if defined(WOLFSSL_SHAKE256) && !defined(WOLFSSL_NO_SHAKE256) wc_Shake shake, shakeCpy; - const char* msg = "Everyone gets Friday off."; - word32 msglen = (word32)XSTRLEN(msg); + const char* msg = TEST_STRING; + word32 msglen = (word32)TEST_STRING_SZ; byte hash[144]; byte hashCpy[144]; word32 hashLen = sizeof(hash); @@ -13887,8 +13897,8 @@ static int test_wc_RabbitProcess (void) const char* key = "\xAC\xC3\x51\xDC\xF1\x62\xFC\x3B" "\xFE\x36\x3D\x2E\x29\x13\x28\x91"; const char* iv = "\x59\x7E\x26\xC1\x75\xF5\x73\xC3"; - const char* input = "Everyone gets Friday off."; - unsigned long int inlen = XSTRLEN(input); + const char* input = TEST_STRING; + unsigned long int inlen = (unsigned long int)TEST_STRING_SZ; /* Initialize stack variables. */ XMEMSET(cipher, 0, sizeof(cipher)); @@ -15225,20 +15235,24 @@ static int test_wc_RsaPublicEncryptDecrypt (void) #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey key; WC_RNG rng; - const char* inStr = "Everyone gets Friday off."; - word32 plainLen = 25; - word32 inLen = (word32)XSTRLEN(inStr); - #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) - int bits = 1024; - word32 cipherLen = 128; - #else - int bits = 2048; - word32 cipherLen = 256; - #endif + const char inStr[] = TEST_STRING; + const word32 plainLen = (word32)TEST_STRING_SZ; + const word32 inLen = (word32)TEST_STRING_SZ; + int bits = TEST_RSA_BITS; + const word32 cipherLen = TEST_RSA_BYTES; + word32 cipherLenResult = cipherLen; - DECLARE_VAR_INIT(in, byte, inLen, inStr, NULL); - DECLARE_VAR(plain, byte, plainLen, NULL); - DECLARE_VAR(cipher, byte, cipherLen, NULL); + DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL); + DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL); + DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL); + +#ifdef DECLARE_VAR_IS_HEAP_ALLOC + if (in == NULL || plain == NULL || cipher == NULL) { + printf("test_wc_RsaPublicEncryptDecrypt malloc failed\n"); + return MEMORY_E; + } +#endif + XMEMCPY(in, inStr, inLen); ret = wc_InitRsaKey(&key, NULL); if (ret == 0) { @@ -15253,7 +15267,7 @@ static int test_wc_RsaPublicEncryptDecrypt (void) if (ret == 0) { ret = wc_RsaPublicEncrypt(in, inLen, cipher, cipherLen, &key, &rng); if (ret >= 0) { - cipherLen = ret; + cipherLenResult = ret; ret = 0; } else { ret = WOLFSSL_FATAL_ERROR; @@ -15276,7 +15290,7 @@ static int test_wc_RsaPublicEncryptDecrypt (void) } #endif if (ret == 0) { - ret = wc_RsaPrivateDecrypt(cipher, cipherLen, plain, plainLen, &key); + ret = wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, plainLen, &key); } if (ret >= 0) { ret = XMEMCMP(plain, inStr, plainLen); @@ -15313,22 +15327,25 @@ static int test_wc_RsaPublicEncryptDecrypt_ex (void) && !defined(NO_SHA) RsaKey key; WC_RNG rng; - const char* inStr = "Everyone gets Friday off."; - word32 inLen = (word32)XSTRLEN(inStr); - const word32 plainSz = 25; + const char inStr[] = TEST_STRING; + const word32 inLen = (word32)TEST_STRING_SZ; + const word32 plainSz = (word32)TEST_STRING_SZ; byte* res = NULL; int idx = 0; - #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) - int bits = 1024; - const word32 cipherSz = 128; - #else - int bits = 2048; - const word32 cipherSz = 256; - #endif + int bits = TEST_RSA_BITS; + const word32 cipherSz = TEST_RSA_BYTES; - DECLARE_VAR_INIT(in, byte, inLen, inStr, NULL); - DECLARE_VAR(plain, byte, plainSz, NULL); - DECLARE_VAR(cipher, byte, cipherSz, NULL); + DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL); + DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL); + DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL); + +#ifdef DECLARE_VAR_IS_HEAP_ALLOC + if (in == NULL || plain == NULL || cipher == NULL) { + printf("test_wc_RsaPublicEncryptDecrypt_exmalloc failed\n"); + return MEMORY_E; + } +#endif + XMEMCPY(in, inStr, inLen); /* Initialize stack structures. */ XMEMSET(&rng, 0, sizeof(rng)); @@ -15431,21 +15448,24 @@ static int test_wc_RsaSSL_SignVerify (void) #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey key; WC_RNG rng; - const char* inStr = "Everyone gets Friday off."; - const word32 plainSz = 25; - word32 inLen = (word32)XSTRLEN(inStr); + const char inStr[] = TEST_STRING; + const word32 plainSz = (word32)TEST_STRING_SZ; + const word32 inLen = (word32)TEST_STRING_SZ; word32 idx = 0; - #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) - int bits = 1024; - const word32 outSz = 128; - #else - int bits = 2048; - const word32 outSz = 256; - #endif + int bits = TEST_RSA_BITS; + const word32 outSz = TEST_RSA_BYTES; - DECLARE_VAR_INIT(in, byte, inLen, inStr, NULL); - DECLARE_VAR(out, byte, outSz, NULL); - DECLARE_VAR(plain, byte, plainSz, NULL); + DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL); + DECLARE_VAR(out, byte, TEST_RSA_BYTES, NULL); + DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL); + +#ifdef DECLARE_VAR_IS_HEAP_ALLOC + if (in == NULL || out == NULL || plain == NULL) { + printf("test_wc_RsaSSL_SignVerify failed\n"); + return MEMORY_E; + } +#endif + XMEMCPY(in, inStr, inLen); ret = wc_InitRsaKey(&key, NULL); @@ -20206,8 +20226,8 @@ static int test_wc_ecc_signVerify_hash (void) #endif word32 siglen = ECC_BUFSIZE; byte sig[ECC_BUFSIZE]; - byte digest[] = "Everyone gets Friday off."; - word32 digestlen = (word32)XSTRLEN((char*)digest); + byte digest[] = TEST_STRING; + word32 digestlen = (word32)TEST_STRING_SZ; /* Init stack var */ XMEMSET(sig, 0, siglen); @@ -21753,7 +21773,7 @@ static int test_wc_ecc_verify_hash_ex (void) mp_int s; unsigned char hash[] = "Everyone gets Friday off.EccSig"; unsigned char iHash[] = "Everyone gets Friday off......."; - unsigned char shortHash[] = "Everyone gets Friday off."; + unsigned char shortHash[] = TEST_STRING; word32 hashlen = sizeof(hash); word32 iHashLen = sizeof(iHash); word32 shortHashLen = sizeof(shortHash); @@ -30286,7 +30306,7 @@ static int test_WOLFSSL_ERROR_MSG (void) int ret = 0; #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\ defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) - const char* msg = "Everyone gets Friday off."; + const char* msg = TEST_STRING; printf(testingFmt, "WOLFSSL_ERROR_MSG()"); diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 552bb65bc..d93b722ac 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -210,6 +210,9 @@ #define TEST_SLEEP() #endif +#define TEST_STRING "Everyone gets Friday off." +#define TEST_STRING_SZ 25 + /* Bit values for each algorithm that is able to be benchmarked. * Common grouping of algorithms also. @@ -2263,8 +2266,8 @@ static void bench_aesgcm_internal(int doAsync, const byte* key, word32 keySz, DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT); DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT); #ifdef DECLARE_VAR_IS_HEAP_ALLOC - if ((bench_additional == NULL) || (bench_tag == NULL)) { - printf("malloc failed\n"); + if (bench_additional == NULL || bench_tag == NULL) { + printf("bench_aesgcm_internal malloc failed\n"); goto exit; } #endif @@ -2748,9 +2751,10 @@ void bench_aesccm(void) DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT); DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT); + #ifdef DECLARE_VAR_IS_HEAP_ALLOC - if ((bench_additional == NULL) || (bench_tag == NULL)) { - printf("malloc failed\n"); + if (bench_additional == NULL || bench_tag == NULL) { + printf("bench_aesccm malloc failed\n"); goto exit; } #endif @@ -4557,13 +4561,13 @@ static void bench_rsa_helper(int doAsync, RsaKey rsaKey[BENCH_MAX_PENDING], int ret = 0, i, times, count = 0, pending = 0; word32 idx = 0; #ifndef WOLFSSL_RSA_VERIFY_ONLY - const char* messageStr = "Everyone gets Friday off."; - const int len = (int)XSTRLEN((char*)messageStr); + const char* messageStr = TEST_STRING; + const int len = (int)TEST_STRING_SZ; #endif double start = 0.0f; const char**desc = bench_desc_words[lng_index]; #ifndef WOLFSSL_RSA_VERIFY_ONLY - DECLARE_VAR_INIT(message, byte, len, messageStr, HEAP_HINT); + DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT); #endif #if !defined(WOLFSSL_MDK5_COMPLv5) /* MDK5 compiler regard this as a executable statement, and does not allow declarations after the line. */ @@ -4603,6 +4607,9 @@ static void bench_rsa_helper(int doAsync, RsaKey rsaKey[BENCH_MAX_PENDING], goto exit; } #endif +#ifndef WOLFSSL_RSA_VERIFY_ONLY + XMEMCPY(message, messageStr, len); +#endif if (!rsa_sign_verify) { #ifndef WOLFSSL_RSA_VERIFY_ONLY @@ -4952,7 +4959,7 @@ void bench_dh(int doAsync) DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT); DECLARE_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT); #ifdef DECLARE_VAR_IS_HEAP_ALLOC - if ((pub[0] == NULL) || (pub2 == NULL) || (agree[0] == NULL) || (priv[0] == NULL) || (priv2 == NULL)) { + if (pub[0] == NULL || pub2 == NULL || agree[0] == NULL || priv[0] == NULL || priv2 == NULL) { ret = MEMORY_E; goto exit; } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c old mode 100644 new mode 100755 index 7f9f1f0e1..e91f7fbe1 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -322,6 +322,9 @@ static int devId = INVALID_DEVID; const char* wnrConfigFile = "wnr-example.conf"; #endif +#define TEST_STRING "Everyone gets Friday off." +#define TEST_STRING_SZ 25 + typedef struct testVector { const char* input; const char* output; @@ -12143,7 +12146,7 @@ static int rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng) { int ret; word32 sigSz; - WOLFSSL_SMALL_STACK_STATIC const byte in[] = "Everyone gets Friday off."; + WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING; WOLFSSL_SMALL_STACK_STATIC const byte hash[] = { 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59, 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe, @@ -12687,8 +12690,8 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) { byte digest[WC_MAX_DIGEST_SIZE]; int ret = 0; - const char* inStr = "Everyone gets Friday off."; - word32 inLen = (word32)XSTRLEN((char*)inStr); + const char inStr[] = TEST_STRING; + word32 inLen = (word32)TEST_STRING_SZ; word32 outSz; word32 plainSz; word32 digestSz; @@ -12729,14 +12732,15 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) #endif }; - DECLARE_VAR_INIT(in, byte, inLen, inStr, HEAP_HINT); + DECLARE_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT); DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT); DECLARE_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT); #ifdef DECLARE_VAR_IS_HEAP_ALLOC - if ((in == NULL) || (out == NULL) || (sig == NULL)) + if (in == NULL || out == NULL || sig == NULL) ERROR_OUT(MEMORY_E, exit_rsa_pss); #endif + XMEMCPY(in, inStr, inLen); /* Test all combinations of hash and MGF. */ for (j = 0; j < (int)(sizeof(hash)/sizeof(*hash)); j++) { @@ -13024,7 +13028,7 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT); #ifdef DECLARE_VAR_IS_HEAP_ALLOC - if ((key == NULL) || (out == NULL) || (plain == NULL)) + if (key == NULL || out == NULL || plain == NULL) ERROR_OUT(MEMORY_E, exit_rsa_nopadding); #endif @@ -13249,7 +13253,7 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key) DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT); #ifdef DECLARE_VAR_IS_HEAP_ALLOC - if ((out == NULL) || (plain == NULL)) + if (out == NULL || plain == NULL) ERROR_OUT(MEMORY_E, exit_rsa_even_mod); #endif @@ -14057,8 +14061,8 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) #endif #if (!defined(WOLFSSL_RSA_VERIFY_ONLY) || defined(WOLFSSL_PUBLIC_MP)) && \ !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) - const char* inStr = "Everyone gets Friday off."; - word32 inLen = (word32)XSTRLEN((char*)inStr); + const char inStr[] = TEST_STRING; + const word32 inLen = (word32)TEST_STRING_SZ; const word32 outSz = RSA_TEST_BYTES; const word32 plainSz = RSA_TEST_BYTES; #endif @@ -14084,15 +14088,16 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) #if (!defined(WOLFSSL_RSA_VERIFY_ONLY) || defined(WOLFSSL_PUBLIC_MP)) && \ !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) - DECLARE_VAR_INIT(in, byte, inLen, inStr, HEAP_HINT); + DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT); DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT); DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT); #endif #ifdef DECLARE_VAR_IS_HEAP_ALLOC - if ((in == NULL) || (out == NULL) || (plain == NULL)) + if (in == NULL || out == NULL || plain == NULL) ERROR_OUT(MEMORY_E, exit_rsa); #endif + XMEMCPY(in, inStr, inLen); #ifdef WOLFSSL_SMALL_STACK if (key == NULL) @@ -18276,7 +18281,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) EVP_PKEY_CTX *enc = NULL; EVP_PKEY_CTX *dec = NULL; - byte in[] = "Everyone gets Friday off."; + byte in[] = TEST_STRING; byte out[256]; size_t outlen; size_t keySz; @@ -19410,7 +19415,7 @@ static int ecc_test_vector_item(const eccVector* vector) if (sig == NULL) ERROR_OUT(MEMORY_E, done); #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) - if (sigRaw == NULL) + if (sigRaw == NULL || r == NULL || s == NULL) ERROR_OUT(MEMORY_E, done); #endif #endif @@ -20406,7 +20411,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #ifdef DECLARE_VAR_IS_HEAP_ALLOC #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && \ !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) - if ((sharedA == NULL) || (sharedB == NULL)) + if (sharedA == NULL || sharedB == NULL) ERROR_OUT(-9900, done); #endif @@ -20416,7 +20421,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #endif #ifdef HAVE_ECC_SIGN - if ((sig == NULL) || (digest == NULL)) + if (sig == NULL || digest == NULL) ERROR_OUT(-9902, done); #endif #endif /* WOLFSSL_SMALL_STACK */ @@ -21100,7 +21105,7 @@ static int ecc_sig_test(WC_RNG* rng, ecc_key* key) word32 sigSz; int size; byte out[ECC_MAX_SIG_SIZE]; - byte in[] = "Everyone gets Friday off."; + byte in[] = TEST_STRING; WOLFSSL_SMALL_STACK_STATIC const byte hash[] = { 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59, 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe, diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index bbab5121f..25a8401a5 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -412,15 +412,7 @@ decouple library dependencies with standard string, memory and so on. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_SMALL_STACK) #define DECLARE_VAR_IS_HEAP_ALLOC #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \ - VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); - #define DECLARE_VAR_INIT(VAR_NAME, VAR_TYPE, VAR_SIZE, INIT_VALUE, HEAP) \ - VAR_TYPE* VAR_NAME = ({ \ - VAR_TYPE* ptr = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT); \ - if (ptr && INIT_VALUE) { \ - XMEMCPY(ptr, INIT_VALUE, sizeof(VAR_TYPE) * VAR_SIZE); \ - } \ - ptr; \ - }) + VAR_TYPE* VAR_NAME = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * VAR_SIZE, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT) #define DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \ VAR_TYPE* VAR_NAME[VAR_ITEMS]; \ int idx##VAR_NAME, inner_idx_##VAR_NAME; \ @@ -453,8 +445,6 @@ decouple library dependencies with standard string, memory and so on. #undef DECLARE_VAR_IS_HEAP_ALLOC #define DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \ VAR_TYPE VAR_NAME[VAR_SIZE] - #define DECLARE_VAR_INIT(VAR_NAME, VAR_TYPE, VAR_SIZE, INIT_VALUE, HEAP) \ - VAR_TYPE* VAR_NAME = (VAR_TYPE*)INIT_VALUE #define DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \ VAR_TYPE VAR_NAME[VAR_ITEMS][VAR_SIZE] #define FREE_VAR(VAR_NAME, HEAP) /* nothing to free, its stack */