PATCH to add xmemdup to libiberty
Marc Espie
espie@quatramaran.ens.fr
Wed Sep 8 02:25:00 GMT 1999
In article < 199909072040.QAA29321@havoc.gtf.org > you write:
>PTR
>xmemdup (input, copy_size, alloc_size)
> const PTR input;
> size_t copy_size;
> size_t alloc_size;
>{
> PTR output = xcalloc (1, alloc_size);
> memcpy (output, input, copy_size);
> return output;
>}
Looks wasteful.
BTW, I think libiberty functions traditionally check xmalloc result,
so that someone may use them with something else than libiberty's xmalloc.
How about
PTR output = xmalloc(alloc_size);
if (output) {
memcpy(output, input, copy_size);
if (alloc_size > copy_size)
memset(output + copy_size, 0, alloc_size - copy_size);
}
return output;
More information about the Gcc-patches
mailing list