RFR-8008118
Christos Zoulas
christos at zoulas.com
Wed Apr 10 20:30:32 UTC 2013
On Apr 10, 11:54am, martinrb at google.com (Martin Buchholz) wrote:
-- Subject: Re: RFR-8008118
| > 1. We did we switch from NEW() to xmalloc()? Why is the xmalloc cast
| > needed?
|
| NEW is for allocating homogeneous arrays, but here the memory block is
| being used for both chars and pointers.
I did not know that. Why the cast though? xmalloc() returns void *, no?
Extraneous casts are bad because they hide conversion errors. For example,
if you don't have the xmalloc prototype in scope, without the cast you
get a warning of casting integer to pointer of different size. With
the cast you get the wrong data assigned to the pointer.
| > 2. I would not declare pathv "const char **", but "char **", and then
| > cast the return if needed. This will make life easier in the future
| > if we decide to turn on warnings about const-castaways.
| >
| >
| I believe the current code doesn't cast away const and doesn't write to
| const. The only cast is to the return from xmalloc, which is expected.
| What might a compiler warn about?
It is casting away const before the memcpy:
+ p = (char *) pathv + pathvsize;
Try to compile with -Wcast-qual.
christos
More information about the core-libs-dev
mailing list