[Mesa-dev] [PATCH 3/3] mesa: Deal with size differences between GLuint and GLhandleARB in GetAttachedObjectsARB

Nicolai Hähnle nhaehnle at gmail.com
Thu Jan 21 09:08:39 PST 2016


On 21.01.2016 11:34, Jeremy Huddleston Sequoia wrote:
>
>> On Jan 21, 2016, at 07:51, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
>>
>> Wow... did you actually run into that crash?
>
> No.  I was just paying attention to compiler warnings ;)

I'm glad someone does ;)

>>
>> On 20.01.2016 20:14, Jeremy Huddleston Sequoia wrote:
>>> Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
>>> ---
>>>   src/mesa/main/shaderapi.c | 12 +++++++++++-
>>>   1 file changed, 11 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
>>> index a988f41..75fc17c 100644
>>> --- a/src/mesa/main/shaderapi.c
>>> +++ b/src/mesa/main/shaderapi.c
>>> @@ -1374,10 +1374,20 @@ _mesa_DetachShader(GLuint program, GLuint shader)
>>>
>>>   void GLAPIENTRY
>>>   _mesa_GetAttachedObjectsARB(GLhandleARB container, GLsizei maxCount,
>>> -                            GLsizei * count, GLhandleARB * obj)
>>> +                            GLsizei * count, GLhandleARB * objARB)
>>>   {
>>> +   int i;
>>> +   GLuint *obj = calloc(maxCount, sizeof(GLuint));
>>> +   assert(obj);
>>> +
>>
>> Is there a precedent for using assert in this way? It feels wrong to me, better set GL_OUT_OF_MEMORY.
>
> Yes, I was just following behavior from elsewhere in the same source file.  In read_shader(), we have:
>     buffer = malloc(shader_size);
>     assert(buffer);
> I'm happy to change that to the following if you think it more appropriate:
>
> GLuint *obj;
> GET_CURRENT_CONTEXT(ctx);
>
> obj = calloc(maxCount, sizeof(GLuint));
> if (!obj) {
>      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
>      return;
> }
> ...

Yes, I'd appreciate that (with the correct function name of course ;)).

>
>>
>>>      GET_CURRENT_CONTEXT(ctx);
>>>      get_attached_shaders(ctx, container, maxCount, count, obj);
>>> +
>>> +   for (i=0 ; i < *count; i++) {
>>> +      objARB[i] = (GLhandleARB)obj[i];
>>
>> Since this can only ever be a widening of the type, you don't really need the cast here.
>
> True.

With those changes, you can add my R-b to this patch as well.

Cheers,
Nicolai

>
>>
>> Nicolai
>>
>>> +   }
>>> +
>>> +   free(obj);
>>>   }
>>>
>>>
>>>
>


More information about the mesa-dev mailing list