[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Don't cast the return of malloc() and friends
From: |
Benno Schulenberg |
Subject: |
Re: [PATCH] Don't cast the return of malloc() and friends |
Date: |
Mon, 31 Aug 2020 12:29:20 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
Op 30-08-2020 om 05:33 schreef Hussam al-Homsi:
> Subject: [PATCH] Don't cast the return of malloc() and friends
>
> Because doing so is superfluous.
It may be redundant, but does it do any harm? I've left those casts in
because they were a nice reminder of what type the allocated memory is for.
Also, if ever the type of one of the relevant variables is changed, the
cast will cause compilation errors -- without the cast the compilation
would silently but probably wrongly succeed.
But... now I see that there already are a few instances that don't use
this cast:
src/help.c: oneline = nmalloc(length + 1);
src/help.c: oneline = nmalloc(length + 5);
src/rcfile.c: error->data = nmalloc(length + 1);
src/rcfile.c: newsc = nmalloc(sizeof(keystruct));
src/rcfile.c: newitem = nmalloc(sizeof(augmentstruct));;
src/text.c: curlint = nmalloc(sizeof(lintstruct));
src/nano.c: bardata = nrealloc(bardata, LINES * sizeof(int));
src/nano.c: bardata = nrealloc(bardata, LINES * sizeof(int));
Now adding casts like (keystruct *) I find ugly. And the types of variables
are extremely unlikely to change at this point in time. So... I will accept.
https://git.savannah.gnu.org/cgit/nano.git/commit/?id=c87bc1d5
Thanks for the patch.
> Remove obsolete charalloc() and charealloc(), too.
>
> Signed-off-by: Hussam al-Homsi <sawuare@gmail.com>
Benno
signature.asc
Description: OpenPGP digital signature