Remove warning about tail "potentially uninitialized"

MSVC was complaining that the `tail` variable was potentially
uninitialized in the while branch. Since the while loop is actually
coupled to the if (head != NULL) that initializes the tail variable,
we move them together, which makes the warning disappear.
This commit is contained in:
Nicolas Léveillé 2016-01-31 16:55:17 +01:00
parent d6e6911ad1
commit 206f5044a8
2 changed files with 10 additions and 9 deletions

View file

@ -52,14 +52,14 @@ HSlist* h_slist_copy(HSlist *slist) {
h_slist_push(ret, head->elem);
tail = ret->head;
head = head->next;
}
while (head != NULL) {
// append head item to tail in a new node
HSlistNode *node = h_arena_malloc(slist->arena, sizeof(HSlistNode));
node->elem = head->elem;
node->next = NULL;
tail = tail->next = node;
head = head->next;
while (head != NULL) {
// append head item to tail in a new node
HSlistNode *node = h_arena_malloc(slist->arena, sizeof(HSlistNode));
node->elem = head->elem;
node->next = NULL;
tail = tail->next = node;
head = head->next;
}
}
return ret;
}

View file

@ -3,7 +3,8 @@ allocator.c
benchmark.c
bitreader.c
bitwriter.c
cfgrammar.c
cfgrammar.c
datastructures.c
desugar.c
glue.c
hammer.c