From 1115f631dc9086639ca5f642daf6403f23a32549 Mon Sep 17 00:00:00 2001 From: Werner Zeh Date: Tue, 12 Mar 2019 07:11:11 +0100 Subject: commonlib/bubblesort: Do not try to sort less than two entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/31854 Tested-by: build bot (Jenkins) Reviewed-by: Kyösti Mälkki Reviewed-by: Arthur Heymans --- src/commonlib/sort.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/commonlib/sort.c b/src/commonlib/sort.c index 40999397c8..350138ec02 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++) { -- cgit v1.2.3