From 71abae18f5a27656302cb0fc076b0cd98df9e9f0 Mon Sep 17 00:00:00 2001 From: Pauli Date: Fri, 9 Oct 2020 09:36:50 +1000 Subject: coverity 1403324 negative array index: check for finding an unknown value and error if so (since it shouldn't happen). Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/13091) --- test/lhash_test.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/lhash_test.c b/test/lhash_test.c index c9dc8b4cee..a9aac5fb86 100644 --- a/test/lhash_test.c +++ b/test/lhash_test.c @@ -33,6 +33,7 @@ static int int_tests[] = { 65537, 13, 1, 3, -5, 6, 7, 4, -10, -12, -14, 22, 9, -17, 16, 17, -23, 35, 37, 173, 11 }; static const unsigned int n_int_tests = OSSL_NELEM(int_tests); static short int_found[OSSL_NELEM(int_tests)]; +static short int_not_found; static unsigned long int int_hash(const int *p) { @@ -56,12 +57,22 @@ static int int_find(int n) static void int_doall(int *v) { - int_found[int_find(*v)]++; + const int n = int_find(*v); + + if (n < 0) + int_not_found++; + else + int_found[n]++; } static void int_doall_arg(int *p, short *f) { - f[int_find(*p)]++; + const int n = int_find(*p); + + if (n < 0) + int_not_found++; + else + f[n]++; } IMPLEMENT_LHASH_DOALL_ARG(int, short); @@ -124,7 +135,12 @@ static int test_int_lhash(void) /* do_all */ memset(int_found, 0, sizeof(int_found)); + int_not_found = 0; lh_int_doall(h, &int_doall); + if (!TEST_int_eq(int_not_found, 0)) { + TEST_info("lhash int doall encountered a not found condition"); + goto end; + } for (i = 0; i < n_int_tests; i++) if (!TEST_int_eq(int_found[i], 1)) { TEST_info("lhash int doall %d", i); @@ -133,7 +149,12 @@ static int test_int_lhash(void) /* do_all_arg */ memset(int_found, 0, sizeof(int_found)); + int_not_found = 0; lh_int_doall_short(h, int_doall_arg, int_found); + if (!TEST_int_eq(int_not_found, 0)) { + TEST_info("lhash int doall arg encountered a not found condition"); + goto end; + } for (i = 0; i < n_int_tests; i++) if (!TEST_int_eq(int_found[i], 1)) { TEST_info("lhash int doall arg %d", i); -- cgit v1.2.3