1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-08 08:58:00 +00:00

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.
This commit is contained in:
Simon Tatham 2024-12-19 08:30:07 +00:00
parent 27550b02e2
commit c2077f888c

View File

@ -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",