This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [top-level] C++-friendly allocators for libiberty
On Mon, 28 Jun 2004, Bernardo Innocenti wrote:
> Andrew Cagney wrote:
> >>Andrew Cagney wrote:
> >>Hmmm... What's the advantage of using XZALLOC over XCALLOC?
> >
> > It avoids that extra argument (but yes, XZALLOC should be implemented
> > using XCALLOC).
>
> Yes, I've always hated the few C library functions with size/number
> of elements pair, as if the caller couldn't do multiplications.
> (fread() and fwrite() come to mind.)
While I generally agree with this view of such functions (fread and fwrite
are worse than calloc, as if the item size isn't 1 you cannot use them
reliably in the presence of possible interrupts by signals), they do at
least if properly implemented check for integer overflow in the
multiplication. See glibc's calloc for how to avoid a division in most
cases in this check, and gnulib's xalloc.h for optimizing the case where
the element size is a constant.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)