summaryrefslogtreecommitdiffstats
path: root/src/commonlib
diff options
context:
space:
mode:
authorWerner Zeh <werner.zeh@siemens.com>2019-03-12 07:11:11 +0100
committerWerner Zeh <werner.zeh@siemens.com>2019-03-14 07:48:06 +0000
commit1115f631dc9086639ca5f642daf6403f23a32549 (patch)
treed2ec7b8bf557a675c603aa4573a730491440597f /src/commonlib
parentfedb36e3c849685e2dbf1b6feb2e936a559f9bfb (diff)
downloadcoreboot-1115f631dc9086639ca5f642daf6403f23a32549.tar.gz
coreboot-1115f631dc9086639ca5f642daf6403f23a32549.tar.bz2
coreboot-1115f631dc9086639ca5f642daf6403f23a32549.zip
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>
Diffstat (limited to 'src/commonlib')
-rw-r--r--src/commonlib/sort.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/commonlib/sort.c b/src/commonlib/sort.c
index 40999397c876..350138ec0215 100644
--- a/src/commonlib/sort.c
+++ b/src/commonlib/sort.c
@@ -23,6 +23,10 @@ void bubblesort(int *v, size_t num_entries, sort_order_t order)
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++) {