[Piglit] [PATCH] texelFetch: Fix incorrect sizeof.

Vinson Lee vlee at freedesktop.org
Mon Jan 14 21:47:04 PST 2013


On Mon, Jan 14, 2013 at 7:24 AM, Brian Paul <brianp at vmware.com> wrote:
> On 01/11/2013 12:28 AM, Vinson Lee wrote:
>>
>> Fixes sizeof not portable defect reported by Coverity.
>>
>> Fixes allocator sizeof operand mismatch bug reported by Clang Static
>> Analyzer.
>>
>> Signed-off-by: Vinson Lee<vlee at freedesktop.org>
>> ---
>>   tests/texturing/shaders/texelFetch.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tests/texturing/shaders/texelFetch.c
>> b/tests/texturing/shaders/texelFetch.c
>> index 78a4162..50e91a6 100644
>> --- a/tests/texturing/shaders/texelFetch.c
>> +++ b/tests/texturing/shaders/texelFetch.c
>> @@ -297,7 +297,7 @@ generate_texture()
>>         expected_colors = calloc(miplevels, sizeof(float **));
>>
>>         for (l = 0; l<  miplevels; l++) {
>> -               expected_colors[l] = calloc(level_size[l][2], sizeof(float
>> **));
>> +               expected_colors[l] = calloc(level_size[l][2], sizeof(float
>> *));
>>
>>                 i_ptr = i_level =
>>                         malloc(level_size[l][0] * level_size[l][1] *
>
>
> Since expected_colors is declared as
>
> float ***expected_colors;
>
> sizeof(float **) would seem to be the right expression.  But sizeof(float *)
> is the same size so I guess this is OK.  Maybe put a comment there saying
> "use sizeof(float *) to silence Clang Static Analyzer warning".
>
> Reviewed-by: Brian Paul <brianp at vmware.com>

I think both Coverity and Clang are correct here and no comment is needed.

The calloc in question is for expected_colors[l] and not for
expected_colors. expected_colors[l] is of type float** and the
allocation should be a multiple of sizeof(float *).


More information about the Piglit mailing list