aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-03-28 14:13:51 -0700
committerJunio C Hamano <gitster@pobox.com>2024-03-28 14:13:51 -0700
commit8e2422320cd7f488e6200a2c998bbdb2827c3d8c (patch)
tree60c7d8c7e270aaab6b5f2185631b91523e8d7f7c
parentb31d4663655c562604db9d166d672d0c29ac99f1 (diff)
parent30ff05094c145397d88ead89c3937d1a058ed98a (diff)
downloadgit-8e2422320cd7f488e6200a2c998bbdb2827c3d8c.tar.gz
Merge branch 'rs/t-prio-queue-fixes'
Test clean-up. * rs/t-prio-queue-fixes: t-prio-queue: check result array bounds t-prio-queue: shorten array index message
-rw-r--r--t/unit-tests/t-prio-queue.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c
index d78b002f9e..5358346361 100644
--- a/t/unit-tests/t-prio-queue.c
+++ b/t/unit-tests/t-prio-queue.c
@@ -19,11 +19,13 @@ static int show(int *v)
return v ? *v : MISSING;
}
-static void test_prio_queue(int *input, int *result, size_t input_size)
+static void test_prio_queue(int *input, size_t input_size,
+ int *result, size_t result_size)
{
struct prio_queue pq = { intcmp };
+ int j = 0;
- for (int i = 0, j = 0; i < input_size; i++) {
+ for (int i = 0; i < input_size; i++) {
void *peek, *get;
switch(input[i]) {
case GET:
@@ -31,16 +33,22 @@ static void test_prio_queue(int *input, int *result, size_t input_size)
get = prio_queue_get(&pq);
if (!check(peek == get))
return;
- if(!check_int(result[j++], ==, show(get)))
- test_msg("failed at result[] index %d", j-1);
+ if (!check_uint(j, <, result_size))
+ break;
+ if (!check_int(result[j], ==, show(get)))
+ test_msg(" j: %d", j);
+ j++;
break;
case DUMP:
while ((peek = prio_queue_peek(&pq))) {
get = prio_queue_get(&pq);
if (!check(peek == get))
return;
- if(!check_int(result[j++], ==, show(get)))
- test_msg("failed at result[] index %d", j-1);
+ if (!check_uint(j, <, result_size))
+ break;
+ if (!check_int(result[j], ==, show(get)))
+ test_msg(" j: %d", j);
+ j++;
}
break;
case STACK:
@@ -54,6 +62,7 @@ static void test_prio_queue(int *input, int *result, size_t input_size)
break;
}
}
+ check_uint(j, ==, result_size);
clear_prio_queue(&pq);
}
@@ -77,7 +86,8 @@ static void test_prio_queue(int *input, int *result, size_t input_size)
{ \
int input[] = {INPUT}; \
int result[] = {RESULT}; \
- test_prio_queue(input, result, ARRAY_SIZE(input)); \
+ test_prio_queue(input, ARRAY_SIZE(input), \
+ result, ARRAY_SIZE(result)); \
}
TEST_INPUT(BASIC_INPUT, BASIC_RESULT, basic)