summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2012-10-14 13:15:32 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2012-10-14 13:19:15 (GMT)
commit9cf45f0c658b583ee1ebdcb3d6345ad290993d68 (patch) (side-by-side diff)
tree2026a3e4fae1ad7e68cd5e3ff01446605e1a7df8 /src
parent740068b42c4097515a0c531209cc6b49c4453426 (diff)
downloadgrecs-9cf45f0c658b583ee1ebdcb3d6345ad290993d68.tar.gz
grecs-9cf45f0c658b583ee1ebdcb3d6345ad290993d68.tar.bz2
Fix list sort in case of an already sorted input.
* src/sort.c (_qsort_nodelist): Avoid infinite recursion on an already sorted input. * tests/sort00.at: New file. * tests/sort01.at: New file. * tests/Makefile.am: Add new test cases. * tests/testsuite.at: Likewise.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/sort.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/sort.c b/src/sort.c
index 0f9b93d..c5ba091 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -95,13 +95,15 @@ _qsort_nodelist(struct node_list *list,
cur = next;
}
- /* Sort both sublists recursively */
- _qsort_nodelist(&low_list, compare);
- _qsort_nodelist(&high_list, compare);
-
- /* Join both lists in order */
- node_list_join(&low_list, &high_list);
-
+ if (!low_list.head)
+ low_list = high_list;
+ else if (high_list.head) {
+ /* Sort both sublists recursively */
+ _qsort_nodelist(&low_list, compare);
+ _qsort_nodelist(&high_list, compare);
+ /* Join both lists in order */
+ node_list_join(&low_list, &high_list);
+ }
/* Return the resulting list */
list->head = low_list.head;
list->tail = low_list.tail;

Return to:

Send suggestions and report system problems to the System administrator.