Werner Zeh merged this change.
commonlib/bubblesort: Do not try to sort less than two entries
Before start sorting check for the number of entries in the data set. If
there are less than two entries, sorting makes no sense.
Change-Id: Ib9d5522cdebb6559a025217f7faf318589d55a2c
Signed-off-by: Werner Zeh <werner.zeh@siemens.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/31854
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
---
M src/commonlib/sort.c
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/commonlib/sort.c b/src/commonlib/sort.c
index 4099939..350138e 100644
--- a/src/commonlib/sort.c
+++ b/src/commonlib/sort.c
@@ -23,6 +23,10 @@
size_t i, j;
int swapped;
+ /* Make sure there are at least two entries to sort. */
+ if (num_entries < 2)
+ return;
+
for (j = 0; j < num_entries - 1; j++) {
swapped = 0;
for (i = 0; i < num_entries - j - 1; i++) {
To view, visit change 31854. To unsubscribe, or for help writing mail filters, visit settings.