diff options
author | Pauli <paul.dale@oracle.com> | 2017-08-17 10:10:07 +1000 |
---|---|---|
committer | Pauli <paul.dale@oracle.com> | 2017-09-28 06:53:40 +1000 |
commit | 1b3e2bbf64b96f636277ca29b31ba152c1831e74 (patch) | |
tree | 10a9f89306c04e3133f5e9c231e6aa4aa2a8841a /test/stack_test.c | |
parent | 9f9442918aeaed5dc2442d81ab8d29fe3e1fb906 (diff) | |
download | openssl-1b3e2bbf64b96f636277ca29b31ba152c1831e74.zip openssl-1b3e2bbf64b96f636277ca29b31ba152c1831e74.tar.gz openssl-1b3e2bbf64b96f636277ca29b31ba152c1831e74.tar.bz2 |
Add a reserve call to the stack data structure.
This allows the caller to guarantee that there is sufficient space for a
number of insertions without reallocation.
The expansion ratio when reallocating the array is reduced to 1.5 rather than 2.
Change bounds testing to use a single size rather than both INT_MAX and
SIZE_MAX. This simplifies some of the tests.
Switch the stack pointers to data from char * to void *
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4386)
Diffstat (limited to 'test/stack_test.c')
-rw-r--r-- | test/stack_test.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/test/stack_test.c b/test/stack_test.c index c0ec46a..680f68d 100644 --- a/test/stack_test.c +++ b/test/stack_test.c @@ -50,7 +50,7 @@ static int int_compare(const int *const *a, const int *const *b) return 0; } -static int test_int_stack(void) +static int test_int_stack(int reserve) { static int v[] = { 1, 2, -4, 16, 999, 1, -173, 1, 9 }; static int notpresent = -1; @@ -84,6 +84,10 @@ static int test_int_stack(void) int i; int testresult = 0; + if (!TEST_ptr(s) + || (reserve > 0 && !TEST_true(sk_sint_reserve(s, 5 * reserve)))) + goto end; + /* Check push and num */ for (i = 0; i < n; i++) { if (!TEST_int_eq(sk_sint_num(s), i)) { @@ -167,7 +171,7 @@ static int uchar_compare(const unsigned char *const *a, return **a - (signed int)**b; } -static int test_uchar_stack(void) +static int test_uchar_stack(int reserve) { static const unsigned char v[] = { 1, 3, 7, 5, 255, 0 }; const int n = OSSL_NELEM(v); @@ -175,6 +179,10 @@ static int test_uchar_stack(void) int i; int testresult = 0; + if (!TEST_ptr(s) + || (reserve > 0 && !TEST_true(sk_uchar_reserve(s, 5 * reserve)))) + goto end; + /* unshift and num */ for (i = 0; i < n; i++) { if (!TEST_int_eq(sk_uchar_num(s), i)) { @@ -364,8 +372,8 @@ end: int setup_tests(void) { - ADD_TEST(test_int_stack); - ADD_TEST(test_uchar_stack); + ADD_ALL_TESTS(test_int_stack, 4); + ADD_ALL_TESTS(test_uchar_stack, 4); ADD_TEST(test_SS_stack); ADD_TEST(test_SU_stack); return 1; |