[Mesa-dev] [PATCH 5/9] glsl: Fix memcpy size in ir_constant
Juha-Pekka Heikkilä
juhapekka.heikkila at gmail.com
Sun Feb 9 01:50:13 PST 2014
The place which cause Klocwork to highlight this is at
src/mesa/main/ff_fragment_shader.cpp around line 897 where it says:
...
float const_data[4] = {
float(1 << rgb_shift),
float(1 << rgb_shift),
float(1 << rgb_shift),
float(1 << alpha_shift)
};
shift = new(p->mem_ctx) ir_constant(glsl_type::vec4_type,
(ir_constant_data *)const_data);
...
I don't know if this is the only place for such usage but it looks
reasonable to me.
If I fix this place instead of what my patch does Klocwork would tell
where is next similar usage for this ir_constant constructor, that is
if such exist.
/Juha-Pekka
On Sat, Feb 8, 2014 at 2:30 AM, Ian Romanick <idr at freedesktop.org> wrote:
> On 02/07/2014 04:44 AM, Juha-Pekka Heikkila wrote:
>> ir_constant::ir_constant(const struct glsl_type,
>> const ir_constant_data *) was copying too much memory.
>
> The code looks correct as-is to me. This copies one ir_constant_data
> union to another... they're declared as the same type, and they have the
> same size. What is the actual error? Is there some code somewhere
> that's casting a different type to ir_constant_data* to pass into this
> constructor?
>
>> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
>> ---
>> src/glsl/ir.cpp | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
>> index 1a36bd6..abc5568 100644
>> --- a/src/glsl/ir.cpp
>> +++ b/src/glsl/ir.cpp
>> @@ -622,7 +622,7 @@ ir_constant::ir_constant(const struct glsl_type *type,
>>
>> this->ir_type = ir_type_constant;
>> this->type = type;
>> - memcpy(& this->value, data, sizeof(this->value));
>> + memcpy(& this->value, data, type->std140_size(false));
>> }
>>
>> ir_constant::ir_constant(float f, unsigned vector_elements)
>>
>
More information about the mesa-dev
mailing list