mesa: fix incorrect type when allocating arrays

Submitted by Andres Rodriguez on Feb. 7, 2018, 7:46 p.m.

Details

Message ID 20180207194638.21992-1-andresx7@gmail.com
State New
Headers show
Series "mesa: fix incorrect type when allocating arrays" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Andres Rodriguez Feb. 7, 2018, 7:46 p.m.
The array members are have type 'struct gl_buffer_object *'

Found by coverity.

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
---

I think this should fix the issue, if I'm interpreting
the coverity message correctly.


 src/mesa/main/externalobjects.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index 35545c2e55..56bf817a6e 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -719,52 +719,52 @@  _mesa_WaitSemaphoreEXT(GLuint semaphore,
    struct gl_semaphore_object *semObj = NULL;
    struct gl_buffer_object **bufObjs = NULL;
    struct gl_texture_object **texObjs = NULL;
 
    const char *func = "glWaitSemaphoreEXT";
 
    if (!ctx->Extensions.EXT_semaphore) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
       return;
    }
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    semObj = _mesa_lookup_semaphore_object(ctx, semaphore);
    if (!semObj)
       return;
 
    FLUSH_VERTICES(ctx, 0);
    FLUSH_CURRENT(ctx, 0);
 
-   bufObjs = malloc(sizeof(struct gl_buffer_object **) * numBufferBarriers);
+   bufObjs = malloc(sizeof(struct gl_buffer_object *) * numBufferBarriers);
    if (!bufObjs) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numBufferBarriers=%u)",
                   func, numBufferBarriers);
       goto end;
    }
 
    for (unsigned i = 0; i < numBufferBarriers; i++) {
       bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
    }
 
-   texObjs = malloc(sizeof(struct gl_texture_object **) * numTextureBarriers);
+   texObjs = malloc(sizeof(struct gl_texture_object *) * numTextureBarriers);
    if (!texObjs) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numTextureBarriers=%u)",
                   func, numTextureBarriers);
       goto end;
    }
 
    for (unsigned i = 0; i < numTextureBarriers; i++) {
       texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
    }
 
    ctx->Driver.ServerWaitSemaphoreObject(ctx, semObj,
                                          numBufferBarriers, bufObjs,
                                          numTextureBarriers, texObjs,
                                          srcLayouts);
 
 end:
    free(bufObjs);
    free(texObjs);
 }
 
@@ -780,52 +780,52 @@  _mesa_SignalSemaphoreEXT(GLuint semaphore,
    struct gl_semaphore_object *semObj = NULL;
    struct gl_buffer_object **bufObjs = NULL;
    struct gl_texture_object **texObjs = NULL;
 
    const char *func = "glSignalSemaphoreEXT";
 
    if (!ctx->Extensions.EXT_semaphore) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
       return;
    }
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    semObj = _mesa_lookup_semaphore_object(ctx, semaphore);
    if (!semObj)
       return;
 
    FLUSH_VERTICES(ctx, 0);
    FLUSH_CURRENT(ctx, 0);
 
-   bufObjs = malloc(sizeof(struct gl_buffer_object **) * numBufferBarriers);
+   bufObjs = malloc(sizeof(struct gl_buffer_object *) * numBufferBarriers);
    if (!bufObjs) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numBufferBarriers=%u)",
                   func, numBufferBarriers);
       goto end;
    }
 
    for (unsigned i = 0; i < numBufferBarriers; i++) {
       bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
    }
 
-   texObjs = malloc(sizeof(struct gl_texture_object **) * numTextureBarriers);
+   texObjs = malloc(sizeof(struct gl_texture_object *) * numTextureBarriers);
    if (!texObjs) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numTextureBarriers=%u)",
                   func, numTextureBarriers);
       goto end;
    }
 
    for (unsigned i = 0; i < numTextureBarriers; i++) {
       texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
    }
 
    ctx->Driver.ServerSignalSemaphoreObject(ctx, semObj,
                                            numBufferBarriers, bufObjs,
                                            numTextureBarriers, texObjs,
                                            dstLayouts);
 
 end:
    free(bufObjs);
    free(texObjs);
 }
 

Comments

On Wed, Feb 7, 2018 at 11:46 AM, Andres Rodriguez <andresx7@gmail.com> wrote:
> The array members are have type 'struct gl_buffer_object *'
>
> Found by coverity.
>
> Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
> ---
>
> I think this should fix the issue, if I'm interpreting
> the coverity message correctly.

Yep, that matches my understanding. Thanks!

Reviewed-by: Matt Turner <mattst88@gmail.com>
Pushed, thanks for the report.


On 2018-02-07 02:47 PM, Matt Turner wrote:
> On Wed, Feb 7, 2018 at 11:46 AM, Andres Rodriguez <andresx7@gmail.com> wrote:
>> The array members are have type 'struct gl_buffer_object *'
>>
>> Found by coverity.
>>
>> Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
>> ---
>>
>> I think this should fix the issue, if I'm interpreting
>> the coverity message correctly.
> 
> Yep, that matches my understanding. Thanks!
> 
> Reviewed-by: Matt Turner <mattst88@gmail.com>
>