lp: Don't allocate sampler functions if count is 0

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 <scerveau@igalia.com>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36165>
(cherry picked from commit b781ae57a5)
This commit is contained in:
Lucas Fryzek 2025-07-18 09:13:05 -04:00 committed by Eric Engestrom
parent 28f746569c
commit 13e1adcd0f
2 changed files with 9 additions and 6 deletions

View file

@ -3634,7 +3634,7 @@
"description": "lp: Don't allocate sampler functions if count is 0",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -874,11 +874,14 @@ llvmpipe_register_texture(struct llvmpipe_context *ctx, struct lp_static_texture
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;