[Mesa-dev] [PATCH] mesa/main: Fix memset in formatquery.c

Alejandro PiƱeiro apinheiro at igalia.com
Fri Mar 17 09:00:17 UTC 2017


On 17/03/17 06:26, Edward O'Callaghan wrote:
> We memset number of elements without multiplication by the
> element size.
>
> Signed-off-by: Edward O'Callaghan <funfunctor at folklore1984.net>
> ---
>  src/mesa/main/formatquery.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/mesa/main/formatquery.c b/src/mesa/main/formatquery.c
> index 598d34d..50d7c31 100644
> --- a/src/mesa/main/formatquery.c
> +++ b/src/mesa/main/formatquery.c
> @@ -1564,7 +1564,7 @@ _mesa_GetInternalformati64v(GLenum target, GLenum internalformat,
>      * no pname can return a negative value, we fill params32 with negative
>      * values as reference values, that can be used to know what copy-back to
>      * params */
> -   memset(params32, -1, 16);

Urgh. Yes, this code is wrong, sorry. When I wrote it the idea is
initialize params32 elements to -1. But memset initilizes byte-per-byte.
Im not even sure if the resulting GLint value is still negative as intended.

> +   memset(params32, -1, 16*sizeof(GLint));

Thanks for the patch, but this just ensures that all the array is
initialized, but it is still initialized to the wrong value.

The correct solution would be initialize params32 to the correct values.

I think that we can just forget about the memset and define params32 as:
   GLint params32[16] = { [0 ... 15] = -1 };

and then move the comment that starts with "For SAMPLES ..." to the
bottom, and replace the "We only copy-back ..." one

Thanks for catching this
>  
>     /* For GL_MAX_COMBINED_DIMENSIONS we need to get back 2 32-bit integers,
>      * and at the same time we only need 2. So for that pname, we call the




More information about the mesa-dev mailing list