From c2077f888c4076c7a872477dbfe4dafcc92d978a Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 19 Dec 2024 08:30:07 +0000 Subject: [PATCH] Fix compile warnings in tree234 tests. I'm not sure why these have never bothered me before, but a test build I just made for a completely different reason complained about them! findtest() did a binary search using a while loop, and then used variables set in the loop body, which gcc objected to on the grounds that the body might have run 0 times and not initialised those variables. Also in the same function gcc objected to the idea that findrelpos234() might have returned NULL and not set 'index'. I think neither of these things can actually have _happened_, but let's stop the compiler complaining anyway. --- utils/tree234.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/tree234.c b/utils/tree234.c index 463f218c..004cfb8d 100644 --- a/utils/tree234.c +++ b/utils/tree234.c @@ -1398,7 +1398,8 @@ void findtest(void) lo = 0; hi = arraylen - 1; - while (lo <= hi) { + assert(lo <= hi); + do { mid = (lo + hi) / 2; c = strcmp(p, array[mid]); if (c < 0) @@ -1407,7 +1408,7 @@ void findtest(void) lo = mid + 1; else break; - } + } while (lo <= hi); if (c == 0) { if (rel == REL234_LT) @@ -1428,10 +1429,11 @@ void findtest(void) ret = NULL; } + index = -1; realret = findrelpos234(tree, p, NULL, rel, &index); if (realret != ret) { error("find(\"%s\",%s) gave %s should be %s", - p, relnames[j], realret, ret); + p, relnames[j], realret ? realret : "NULL", ret); } if (realret && index != mid) { error("find(\"%s\",%s) gave %d should be %d",