mirror of
https://github.com/jrcutler/threadless.io.git
synced 2024-07-07 10:35:49 +00:00
Check size after allocation_realloc_array test calls.
This commit is contained in:
parent
75d8f63842
commit
0eed022034
@ -11,6 +11,8 @@
|
||||
/* HAVE_* */
|
||||
#include "config.h"
|
||||
|
||||
/* errno, EINVAL */
|
||||
#include <errno.h>
|
||||
/* printf, perror */
|
||||
#include <stdio.h>
|
||||
/* EXIT_SUCCESS, EXIT_FAILURE */
|
||||
@ -26,6 +28,18 @@
|
||||
#include <threadless/allocation.h>
|
||||
|
||||
|
||||
static int test_allocation(allocation_t *allocation, size_t size)
|
||||
{
|
||||
int error = allocation_realloc_array(allocation, 1, size);
|
||||
if (!error && allocation->size != size) {
|
||||
/* bad size */
|
||||
errno = EINVAL;
|
||||
error = -1;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
static int run(allocator_t *allocator)
|
||||
{
|
||||
int error = 0;
|
||||
@ -35,16 +49,23 @@ static int run(allocator_t *allocator)
|
||||
allocation_init(&allocation, allocator);
|
||||
|
||||
for (size = 1; !error && size < (1 << 22); size = size << 1) {
|
||||
error = allocation_realloc_array(&allocation, 1, size);
|
||||
error = test_allocation(&allocation, size);
|
||||
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
size_t big = 1UL << (sizeof(size_t) * 4);
|
||||
size = allocation.size;
|
||||
error = !allocation_realloc_array(&allocation, big, big);
|
||||
if (!error && allocation.size != size) {
|
||||
/* bad size */
|
||||
errno = EINVAL;
|
||||
error = -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (size = 1 << 22; !error && size; size = size >> 1) {
|
||||
error = allocation_realloc_array(&allocation, 1, size);
|
||||
error = test_allocation(&allocation, size);
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user