[Piglit] [PATCH] util-cl: Fix non-portable sizeof.

Matt Turner mattst88 at gmail.com
Wed Dec 17 11:21:41 PST 2014


On Wed, Dec 17, 2014 at 11:20 AM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> On Wed, Dec 17, 2014 at 2:17 PM, Matt Turner <mattst88 at gmail.com> wrote:
>> On Tue, Dec 16, 2014 at 10:47 PM, Vinson Lee <vlee at freedesktop.org> wrote:
>>> Fix Coverity "sizeof not portable" defect.
>>>
>>> Signed-off-by: Vinson Lee <vlee at freedesktop.org>
>>> ---
>>>  tests/util/piglit-framework-cl-program.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tests/util/piglit-framework-cl-program.c b/tests/util/piglit-framework-cl-program.c
>>> index d335486..f94525b 100644
>>> --- a/tests/util/piglit-framework-cl-program.c
>>> +++ b/tests/util/piglit-framework-cl-program.c
>>> @@ -287,7 +287,7 @@ piglit_cl_program_test_run(const int argc,
>>>         } else if(config->program_binary_file != NULL) {
>>>                 unsigned int length;
>>>                 size_t* lengths = malloc(sizeof(size_t) * env.context->num_devices);
>>> -               unsigned char** program_binaries = malloc(sizeof(unsigned char**) * env.context->num_devices);
>>> +               unsigned char** program_binaries = malloc(sizeof(unsigned char*) * env.context->num_devices);
>>
>> Someone explain this one to me?
>>
>> program_binaries is an unsigned char ** and that's what we're giving
>> to sizeof. What's wrong with sizeof(unsigned char **)?
>
> It's an array of (unsigned char *), not (unsigned char **). For
> example if it were a 1d array, you might have
>
> unsigned char *foo = malloc(sizeof(unsigned char) * num_elements)
>
> right? Of course it doesn't end up _actually_ mattering, since
> sizeof(char*) == sizeof(char**).
>
>   -ilia

Oh yes, of course. Thanks for doing my thinking for me. :)


More information about the Piglit mailing list