diff --git a/device_mapper/libdm-report.c b/device_mapper/libdm-report.c index aabd03b14..2a0036035 100644 --- a/device_mapper/libdm-report.c +++ b/device_mapper/libdm-report.c @@ -4416,8 +4416,9 @@ static int _sort_rows(struct dm_report *rh) qsort(rows, count, sizeof(**rows), _row_compare); dm_list_init(&rh->rows); - while (count--) - dm_list_add_h(&rh->rows, &(*rows)[count]->list); + + while (count > 0) + dm_list_add_h(&rh->rows, &(*rows)[--count]->list); return 1; } diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c index c015a57fe..863463c84 100644 --- a/libdm/libdm-report.c +++ b/libdm/libdm-report.c @@ -4415,8 +4415,9 @@ static int _sort_rows(struct dm_report *rh) qsort(rows, count, sizeof(**rows), _row_compare); dm_list_init(&rh->rows); - while (count--) - dm_list_add_h(&rh->rows, &(*rows)[count]->list); + + while (count > 0) + dm_list_add_h(&rh->rows, &(*rows)[--count]->list); return 1; }