From b781ae57a50c5992b6603fb4893c908b48b84e6a Mon Sep 17 00:00:00 2001 From: Lucas Fryzek Date: Fri, 18 Jul 2025 09:13:05 -0400 Subject: [PATCH] lp: Don't allocate sampler functions if count is 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents memory being allocated with a size of 0 as the sampler count will be 0. Fixes: #13539 Co-authored-by: Stéphane Cerveau Reviewed-by: Konstantin Seurer Cc: mesa-stable Part-of: --- src/gallium/drivers/llvmpipe/lp_texture_handle.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_texture_handle.c b/src/gallium/drivers/llvmpipe/lp_texture_handle.c index 97b73fa3246..1f3083c276b 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture_handle.c +++ b/src/gallium/drivers/llvmpipe/lp_texture_handle.c @@ -1270,11 +1270,14 @@ llvmpipe_register_texture(struct llvmpipe_context *ctx, struct lp_texture_handle simple_mtx_lock(&matrix->lock); if (entry->sampled) { - if (entry->sample_functions) { - entry->sample_functions = realloc(entry->sample_functions, matrix->sampler_count * sizeof(void **)); - memset(entry->sample_functions + entry->sampler_count, 0, (matrix->sampler_count - entry->sampler_count) * sizeof(void **)); - } else { - entry->sample_functions = calloc(matrix->sampler_count, sizeof(void **)); + if (matrix->sampler_count > 0) { + if (entry->sample_functions) { + entry->sample_functions = realloc(entry->sample_functions, matrix->sampler_count * sizeof(void **)); + memset(entry->sample_functions + entry->sampler_count, 0, + (matrix->sampler_count - entry->sampler_count) * sizeof(void **)); + } else { + entry->sample_functions = calloc(matrix->sampler_count, sizeof(void **)); + } } entry->sampler_count = matrix->sampler_count;