[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nano-devel
Subject:    Re: [PATCH] Don't cast the return of malloc() and friends
From:       Benno Schulenberg <bensberg () telfort ! nl>
Date:       2020-08-31 10:29:20
Message-ID: b9aed95a-3bcd-01bd-09f6-c145d4a56fcf () telfort ! nl
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


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" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic