[Mesa-dev] [PATCH 3/3] Don't cast the return value of malloc/realloc

Jose Fonseca jfonseca at vmware.com
Wed Jan 7 12:18:21 PST 2015


On 08/12/14 19:56, Matt Turner wrote:
> See commit 2b7a972e for the Coccinelle script.
[...]
> diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
> index 4f5a2d1..6945c2f 100644
> --- a/src/mesa/main/imports.c
> +++ b/src/mesa/main/imports.c
> @@ -94,7 +94,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
>
>      ASSERT( alignment > 0 );
>
> -   ptr = (uintptr_t)malloc(bytes + alignment + sizeof(void *));
> +   ptr = malloc(bytes + alignment + sizeof(void *));
>      if (!ptr)
>         return NULL;
>
> @@ -143,7 +143,7 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
>
>      ASSERT( alignment > 0 );
>
> -   ptr = (uintptr_t)calloc(1, bytes + alignment + sizeof(void *));
> +   ptr = calloc(1, bytes + alignment + sizeof(void *));
>      if (!ptr)
>         return NULL;
>

This caused:

src/mesa/main/imports.c: In function ‘_mesa_align_malloc’:
src/mesa/main/imports.c:97:8: warning: assignment makes integer from 
pointer without a cast [enabled by default]
src/mesa/main/imports.c: In function ‘_mesa_align_calloc’:
src/mesa/main/imports.c:146:8: warning: assignment makes integer from 
pointer without a cast [enabled by default]

I believe that these void * <-> int casts are unavoidable.

It looks an isolated case -- the rest of the patch looks OK.


Jose


More information about the mesa-dev mailing list