tc: fix potential overflows

Reported by static analysis. Multiplication may overflow
before being converted to the larger type, so fix this
by casting one of the operands to the destination type.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35877>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2025-06-19 10:17:50 +02:00 committed by Marge Bot
parent 8731293170
commit bd625f7453

View file

@ -3183,13 +3183,16 @@ tc_texture_subdata(struct pipe_context *_pipe,
{
struct threaded_context *tc = threaded_context(_pipe);
uint64_t size;
uint32_t last_row_stride;
assert(box->height >= 1);
assert(box->depth >= 1);
last_row_stride = box->width * util_format_get_blocksize(resource->format);
size = (box->depth - 1) * layer_stride +
(box->height - 1) * (uint64_t)stride +
box->width * util_format_get_blocksize(resource->format);
last_row_stride;
if (!size)
return;