Rename the length argument to TEST_CALLOC() to be the more accurate item_count

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
This commit is contained in:
Tom Cosgrove 2023-07-21 11:34:44 +01:00
parent 05b2a87ea0
commit a45d902822

View File

@ -107,52 +107,52 @@
* The allocated memory will be filled with zeros. * The allocated memory will be filled with zeros.
* *
* You must set \p pointer to \c NULL before calling this macro and * You must set \p pointer to \c NULL before calling this macro and
* put `mbedtls_free( pointer )` in the test's cleanup code. * put `mbedtls_free(pointer)` in the test's cleanup code.
* *
* If \p length is zero, the resulting \p pointer will be \c NULL. * If \p item_count is zero, the resulting \p pointer will be \c NULL.
* This is usually what we want in tests since API functions are * This is usually what we want in tests since API functions are
* supposed to accept null pointers when a buffer size is zero. * supposed to accept null pointers when a buffer size is zero.
* *
* This macro expands to an instruction, not an expression. * This macro expands to an instruction, not an expression.
* It may jump to the \c exit label. * It may jump to the \c exit label.
* *
* \param pointer An lvalue where the address of the allocated buffer * \param pointer An lvalue where the address of the allocated buffer
* will be stored. * will be stored.
* This expression may be evaluated multiple times. * This expression may be evaluated multiple times.
* \param length Number of elements to allocate. * \param item_count Number of elements to allocate.
* This expression may be evaluated multiple times. * This expression may be evaluated multiple times.
* *
*/ */
#define TEST_CALLOC(pointer, length) \ #define TEST_CALLOC(pointer, item_count) \
do { \ do { \
TEST_ASSERT((pointer) == NULL); \ TEST_ASSERT((pointer) == NULL); \
if ((length) != 0) { \ if ((item_count) != 0) { \
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \ (pointer) = mbedtls_calloc(sizeof(*(pointer)), \
(length)); \ (item_count)); \
TEST_ASSERT((pointer) != NULL); \ TEST_ASSERT((pointer) != NULL); \
} \ } \
} while (0) } while (0)
/* For backwards compatibility */ /* For backwards compatibility */
#define ASSERT_ALLOC(pointer, length) TEST_CALLOC(pointer, length) #define ASSERT_ALLOC(pointer, item_count) TEST_CALLOC(pointer, item_count)
/** Allocate memory dynamically. If the allocation fails, skip the test case. /** Allocate memory dynamically. If the allocation fails, skip the test case.
* *
* This macro behaves like #TEST_CALLOC, except that if the allocation * This macro behaves like #TEST_CALLOC, except that if the allocation
* fails, it marks the test as skipped rather than failed. * fails, it marks the test as skipped rather than failed.
*/ */
#define TEST_CALLOC_OR_SKIP(pointer, length) \ #define TEST_CALLOC_OR_SKIP(pointer, item_count) \
do { \ do { \
TEST_ASSERT((pointer) == NULL); \ TEST_ASSERT((pointer) == NULL); \
if ((length) != 0) { \ if ((item_count) != 0) { \
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \ (pointer) = mbedtls_calloc(sizeof(*(pointer)), \
(length)); \ (item_count)); \
TEST_ASSUME((pointer) != NULL); \ TEST_ASSUME((pointer) != NULL); \
} \ } \
} while (0) } while (0)
/* For backwards compatibility */ /* For backwards compatibility */
#define ASSERT_ALLOC_WEAK(pointer, length) TEST_CALLOC_OR_SKIP(pointer, length) #define ASSERT_ALLOC_WEAK(pointer, item_count) TEST_CALLOC_OR_SKIP(pointer, item_count)
/** Compare two buffers and fail the test case if they differ. /** Compare two buffers and fail the test case if they differ.
* *