From 28c977bd25c6b50bde62eeef766310e0cdf96f32 Mon Sep 17 00:00:00 2001 From: Plamena Manolova Date: Mon, 29 Feb 2016 10:19:39 +0200 Subject: [PATCH] link_uniforms: Traverse EmptyUniformLocations safely. Since EmptyUniformLocations is a list of empty spaces inside UniformRemapTable, it would end up being empty if there are no gaps. This would lead to find_empty_block producing a segmentation fault since foreach_list_typed doesn't work with empty lists. This patch accounts for this by checking whether EmptyUniformLocations is empty before iterating through it. This patch also replaces foreach_list_typed with foreach_list_typed_safe since the removal of nodes might lead to a segmentation fault. --- src/compiler/glsl/link_uniforms.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index deaba94..d986839 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -1048,8 +1048,11 @@ find_empty_block(struct gl_shader_program *prog, { const unsigned entries = MAX2(1, uniform->array_elements); - foreach_list_typed(struct empty_uniform_block, block, link, - &prog->EmptyUniformLocations) { + if (exec_list_is_empty(&prog->EmptyUniformLocations)) + return -1; + + foreach_list_typed_safe(struct empty_uniform_block, block, link, + &prog->EmptyUniformLocations) { /* Found a block with enough slots to fit the uniform */ if (block->slots == entries) { unsigned start = block->start; -- 2.4.3