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>
This commit is contained in:
parent
fedb36e3c8
commit
1115f631dc
1 changed files with 4 additions and 0 deletions
|
@ -23,6 +23,10 @@ void bubblesort(int *v, size_t num_entries, sort_order_t order)
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
int swapped;
|
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++) {
|
for (j = 0; j < num_entries - 1; j++) {
|
||||||
swapped = 0;
|
swapped = 0;
|
||||||
for (i = 0; i < num_entries - j - 1; i++) {
|
for (i = 0; i < num_entries - j - 1; i++) {
|
||||||
|
|
Loading…
Reference in a new issue