[Mesa-dev] [PATCH] glsl: add null pointer check in print_without_declaration()

Nicolai Hähnle nhaehnle at gmail.com
Mon Apr 3 08:36:20 UTC 2017


On 31.03.2017 20:14, Brian Paul wrote:
> On 03/31/2017 12:01 AM, Nicolai Hähnle wrote:
>> On 31.03.2017 05:21, Brian Paul wrote:
>>> To avoid/fix a segmentation fault when running the stand-alone GLSL
>>> compiler utility for cases such as the Mesa demos toyball test:
>>>
>>> glsl_compiler --dump-builder --version 120 CH11-toyball.vert
>>> CH11-toyball.frag
>>> ---
>>>  src/compiler/glsl/ir_builder_print_visitor.cpp | 4 +++-
>>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/src/compiler/glsl/ir_builder_print_visitor.cpp
>>> b/src/compiler/glsl/ir_builder_print_visitor.cpp
>>> index 825dbe1..164a237 100644
>>> --- a/src/compiler/glsl/ir_builder_print_visitor.cpp
>>> +++ b/src/compiler/glsl/ir_builder_print_visitor.cpp
>>> @@ -581,7 +581,9 @@
>>> ir_builder_print_visitor::print_without_declaration(const
>>> ir_expression *ir)
>>>           const struct hash_entry *const he =
>>>              _mesa_hash_table_search(index_map, ir->operands[i]);
>>>
>>> -         print_without_indent("r%04X", (unsigned)(uintptr_t) he->data);
>>> +         if (he) {
>>> +            print_without_indent("r%04X", (unsigned)(uintptr_t)
>>> he->data);
>>> +         }
>>
>> Is the output still usable in this case? I don't quite understand the
>> use case and how this case can happen.
>
> I didn't dig either and would appreciate any feedback.  I'm merely
> trying to avoid a segfault (found while debugging the MinGW optimization
> issue).

I'm not really familiar with that code and couldn't figure out from 
looking at it when/why it happens, but at least looking at the 
surrounding code, I'd say that this cannot possibly produce a good 
output when 'he' is NULL. The point is to generate well-formed C++ to be 
compiled later, and skipping the print will just lead to writing out a 
function call with a malformed parameter list.

Maybe the answer is that the --dump-builder simply isn't made for this 
type of use, in which case the question becomes: why do you want to use 
it this way? And if there's a good reason for using it this way, the bug 
needs to be understood properly. Maybe Ian knows more? I believe he 
wrote most of that code.

Nicolai
-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list