lima: fix warning of garbage value access

scan-build complains that an access of reg[j+1] in this code might
return garbage.
Let's take the chance to clean this open coded sorting code up and
just use qsort.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14894>
This commit is contained in:
Erico Nunes 2022-02-04 20:17:26 +01:00 committed by Marge Bot
parent 2d807979c9
commit 60888c95bd
2 changed files with 13 additions and 18 deletions

View file

@ -31,6 +31,13 @@
* Author: Vivek Sarkar, Mauricio J. Serrano, Barbara B. Simons
*/
static int cmp_float(const void *a, const void *b)
{
const float *fa = (const float *) a;
const float *fb = (const float *) b;
return (*fa > *fb) - (*fa < *fb);
}
static void schedule_calc_sched_info(gpir_node *node)
{
int n = 0;
@ -68,15 +75,7 @@ static void schedule_calc_sched_info(gpir_node *node)
}
/* sort */
for (i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (reg[j] > reg[j + 1]) {
float tmp = reg[j + 1];
reg[j + 1] = reg[j];
reg[j] = tmp;
}
}
}
qsort(reg, n, sizeof(reg[0]), cmp_float);
for (i = 0; i < n; i++) {
float pressure = reg[i] + n - (i + 1);

View file

@ -26,6 +26,10 @@
#include "ppir.h"
static int cmp_int(const void *a, const void *b)
{
return (*(int*)a - *(int*)b);
}
static void ppir_schedule_calc_sched_info(ppir_instr *instr)
{
@ -62,15 +66,7 @@ static void ppir_schedule_calc_sched_info(ppir_instr *instr)
}
/* sort */
for (i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (reg[j] > reg[j + 1]) {
int tmp = reg[j + 1];
reg[j + 1] = reg[j];
reg[j] = tmp;
}
}
}
qsort(reg, n, sizeof(reg[0]), cmp_int);
for (i = 0; i < n; i++) {
int pressure = reg[i] + n - (i + 1);