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

Matt Turner mattst88 at gmail.com
Wed Sep 5 10:46:05 PDT 2012


On Wed, Sep 5, 2012 at 10:42 AM, Jose Fonseca <jfonseca at vmware.com> wrote:
> ----- Original Message -----
>> On 09/05/2012 12:42 AM, Matt Turner wrote:
>> > This patch has been generated by the following Coccinelle semantic
>> > patch:
>> >
>> > // Don't cast the return value of malloc/realloc.
>> > //
>> > // Casting the return value of malloc/realloc only stands to hide
>> > // errors.
>>
>> So assigning a void pointer to a non-void pointer is legal in C and
>> illegal in C++.  I seem to recall some people compiling all of Mesa
>> with C++ in some situations in the past.  Also, there were some C
>> compiler(s) years ago that required these casts (can't remember
>> which).
>>
>> I'm kind of on the fence about this change.
>
> I don't care for the *.c files either way, but given we're writing new code in C++ (e.g., glsl, llvm) that often needs to interoperate with the C code, we should leave the *.h files alone in order to retain C++ compatability, or they will need to be undone next time somebody wants to include the headers in question.
>
> Jose

Not a bad idea. The three headers that are modified are from the
radeon (r100) driver, r300g, and a state tracker header. I guess the
first two are okay to modify, and looking at the state tracker header
-- it shouldn't have been modified anyway since it's a *CALLOC_STRUCT
definition that was changed.

Thanks for the review!
Matt


More information about the mesa-dev mailing list