coverity negative array index: check for finding an unknown value and error if so (since it shouldn't happen).
@@ -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);
