fc_sort: initialize allocated memory to fix execution on an empty file
When running fc_sort on an empty context file, this program uses uninitialized pointers when accessing to the elements of a list. On my system, it goes in a very long loop (maybe infinite) because uninitialized fields in malloc'ed structures happen to contain valid pointers in the heap. This patch fixes this bug by initializing ->next and ->data fields before they may be read.
This commit is contained in:
parent
eedc944a54
commit
572c617c91
|
@ -346,6 +346,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Initialize the head of the linked list. */
|
/* Initialize the head of the linked list. */
|
||||||
head = current = (file_context_node_t*)malloc(sizeof(file_context_node_t));
|
head = current = (file_context_node_t*)malloc(sizeof(file_context_node_t));
|
||||||
|
head->next = NULL;
|
||||||
|
|
||||||
/* Parse the file into a file_context linked list. */
|
/* Parse the file into a file_context linked list. */
|
||||||
line_buf = NULL;
|
line_buf = NULL;
|
||||||
|
@ -489,6 +490,8 @@ int main(int argc, char *argv[])
|
||||||
bcurrent = master =
|
bcurrent = master =
|
||||||
(file_context_bucket_t *)
|
(file_context_bucket_t *)
|
||||||
malloc(sizeof(file_context_bucket_t));
|
malloc(sizeof(file_context_bucket_t));
|
||||||
|
bcurrent->next = NULL;
|
||||||
|
bcurrent->data = NULL;
|
||||||
|
|
||||||
/* Go until all the nodes have been put in individual buckets. */
|
/* Go until all the nodes have been put in individual buckets. */
|
||||||
while (current) {
|
while (current) {
|
||||||
|
|
Loading…
Reference in New Issue