Move the overallocation test to test suites
This way the compiler does not complain about an overly large allocation made. Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
parent
aae3208c29
commit
60de0b198a
3 changed files with 16 additions and 12 deletions
|
@ -77,10 +77,7 @@ static int calloc_self_test(int verbose)
|
|||
unsigned int buffer_4_size = 4097; /* Allocate more than the usual page size */
|
||||
unsigned char *buffer3 = mbedtls_calloc(buffer_3_size, 1);
|
||||
unsigned char *buffer4 = mbedtls_calloc(buffer_4_size, 1);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Walloc-size-larger-than="
|
||||
unsigned char *buffer5 = mbedtls_calloc(SIZE_MAX/2, SIZE_MAX/2);
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
if (empty1 == NULL && empty2 == NULL) {
|
||||
if (verbose) {
|
||||
mbedtls_printf(" CALLOC(0,1): passed (NULL)\n");
|
||||
|
@ -175,13 +172,6 @@ static int calloc_self_test(int verbose)
|
|||
}
|
||||
}
|
||||
|
||||
if (buffer5 != NULL) {
|
||||
++failures;
|
||||
if (verbose) {
|
||||
mbedtls_printf(" CALLOC(SIZE_MAX/2, SIZE_MAX/2): failed (returned a valid pointer)\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
mbedtls_printf("\n");
|
||||
}
|
||||
|
@ -191,7 +181,6 @@ static int calloc_self_test(int verbose)
|
|||
mbedtls_free(buffer2);
|
||||
mbedtls_free(buffer3);
|
||||
mbedtls_free(buffer4);
|
||||
mbedtls_free(buffer5);
|
||||
return failures;
|
||||
}
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
|
|
@ -4,3 +4,6 @@ time_get_milliseconds:
|
|||
|
||||
Time: get seconds
|
||||
time_get_seconds:
|
||||
|
||||
Check mbedtls_calloc overallocation
|
||||
check_mbedtls_calloc_overallocation:SIZE_MAX/2:SIZE_MAX/2
|
||||
|
|
|
@ -120,3 +120,15 @@ void time_delay_seconds(int delay_secs)
|
|||
goto exit;
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void check_mbedtls_calloc_overallocation(intmax_t num, intmax_t size)
|
||||
{
|
||||
unsigned char *buf;
|
||||
buf = mbedtls_calloc((size_t) num, (size_t) size);
|
||||
TEST_ASSERT(buf == NULL);
|
||||
|
||||
exit:
|
||||
mbedtls_free(buf);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
Loading…
Reference in a new issue