mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
tree234: avoid an uninitialised-variable warning.
Apparently, some compilers can't work out that the pattern if (!t->root) { special-case handler followed by early return } n = t->root; while (n) { ... } will execute the while loop at least once, on the grounds that the _first_ test for n being non-NULL must pass, because we initialised n from t->root which can't be NULL on any code path where we didn't take the early return. So they might give an uninitialised-variable warning for the variable 'ki', which is initialised inside the while loop. Compilers, eh. But it's easy enough to turn the while into a do-while, so that even the least alert compiler will know it runs at least once.
This commit is contained in:
@ -332,7 +332,7 @@ static void *add234_internal(tree234 *t, void *e, int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n = t->root;
|
n = t->root;
|
||||||
while (n) {
|
do {
|
||||||
LOG((" node %p: %p/%d \"%s\" %p/%d \"%s\" %p/%d \"%s\" %p/%d\n",
|
LOG((" node %p: %p/%d \"%s\" %p/%d \"%s\" %p/%d \"%s\" %p/%d\n",
|
||||||
n,
|
n,
|
||||||
n->kids[0], n->counts[0], n->elems[0],
|
n->kids[0], n->counts[0], n->elems[0],
|
||||||
@ -385,7 +385,7 @@ static void *add234_internal(tree234 *t, void *e, int index) {
|
|||||||
if (!n->kids[ki])
|
if (!n->kids[ki])
|
||||||
break;
|
break;
|
||||||
n = n->kids[ki];
|
n = n->kids[ki];
|
||||||
}
|
} while (n);
|
||||||
|
|
||||||
add234_insert(NULL, e, NULL, &t->root, n, ki);
|
add234_insert(NULL, e, NULL, &t->root, n, ki);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user