mesa/program: fix nir output reg overflow

outputs_written is uint64_t, should count max reg number
by util_last_bit64(). Otherwise the following access will
overflow the allocated array with a smaller size.

cc: mesa-stable

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15765>
This commit is contained in:
Qiang Yu 2022-03-24 11:15:58 +08:00 committed by Marge Bot
parent 28801cfba0
commit feea8fed44

View file

@ -916,7 +916,7 @@ setup_registers_and_variables(struct ptn_compile *c)
}
/* Create output registers and variables. */
int max_outputs = util_last_bit(c->prog->info.outputs_written);
int max_outputs = util_last_bit64(c->prog->info.outputs_written);
c->output_regs = rzalloc_array(c, nir_register *, max_outputs);
uint64_t outputs_written = c->prog->info.outputs_written;