From 09938eee857d07d931e5d3ac968ddd17c5f79d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Tue, 20 May 2025 16:24:03 +0200 Subject: [PATCH] llvmpipe: Asserts that the format at least has one non-void channel As we are using its index as array index, avoid the use of the -1 index there. CID: 1517247, 1517239 Negative array index read Part-of: --- src/gallium/drivers/llvmpipe/lp_state_fs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 4bfccd83e17..4fe5e88dcfe 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -181,6 +181,7 @@ lp_mem_type_from_format_desc(const struct util_format_description *format_desc, } int chan = util_format_get_first_non_void_channel(format_desc->format); + assert(chan >= 0); memset(type, 0, sizeof(struct lp_type)); type->floating = format_desc->channel[chan].type == UTIL_FORMAT_TYPE_FLOAT; @@ -1783,7 +1784,8 @@ lp_blend_type_from_format_desc(const struct util_format_description *format_desc return; } - const int chan = util_format_get_first_non_void_channel(format_desc->format); + int chan = util_format_get_first_non_void_channel(format_desc->format); + assert(chan >= 0); memset(type, 0, sizeof(struct lp_type)); type->floating = format_desc->channel[chan].type == UTIL_FORMAT_TYPE_FLOAT;