mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-20 21:39:54 +00:00
Introduce TEST_CALLOC_NONNULL
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
ba600b2fd9
commit
a328635305
@ -143,6 +143,32 @@
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/** Allocate memory dynamically and fail the test case if this fails.
|
||||
* The allocated memory will be filled with zeros.
|
||||
*
|
||||
* You must set \p pointer to \c NULL before calling this macro and
|
||||
* put `mbedtls_free(pointer)` in the test's cleanup code.
|
||||
*
|
||||
* If \p item_count is zero, the resulting \p pointer will not be \c NULL.
|
||||
*
|
||||
* This macro expands to an instruction, not an expression.
|
||||
* It may jump to the \c exit label.
|
||||
*
|
||||
* \param pointer An lvalue where the address of the allocated buffer
|
||||
* will be stored.
|
||||
* This expression may be evaluated multiple times.
|
||||
* \param item_count Number of elements to allocate.
|
||||
* This expression may be evaluated multiple times.
|
||||
*
|
||||
*/
|
||||
#define TEST_CALLOC_NONNULL(pointer, item_count) \
|
||||
do { \
|
||||
TEST_ASSERT((pointer) == NULL); \
|
||||
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
|
||||
(item_count)); \
|
||||
TEST_ASSERT((pointer) != NULL); \
|
||||
} while (0)
|
||||
|
||||
/* For backwards compatibility */
|
||||
#define ASSERT_ALLOC(pointer, item_count) TEST_CALLOC(pointer, item_count)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user