RPM Community Forums

Mailing List Message of <popt-devel>

Re: Question about the xmalloc() et al functions

From: Wayne Davison <wayned@samba.org>
Date: Mon 10 Mar 2008 - 03:00:52 CET
Message-ID: <20080310020052.GC15135@herod.dreamhost.com>
On Sun, Mar 09, 2008 at 08:27:25PM -0400, Jeff Johnson wrote:
> Using xmalloc just opens up a can-of-worms while lusers fuss about
> non-gcc compiler extension portability.

Aha, I had failed to notice that the "? :" bit was a gcc extension.

What I don't like is that normal users get some memory functions that
are fatal if they use gcc, while all others get non-fatal functions.
Perhaps the default should be for all normal compiles to get the non-
fatal functions, and then anyone that wanted to use the current gcc
defines could set something extra (such as -DFATAL_MEM).

One other reason I care about this is that I think the various bits of
code that are doing a strdup()-like action should be using a strdup()-
like call, not each one having their own set of strlen/malloc/strcpy
calls.  It's clearer and a bit safer.

I'm attaching a patch that adds the extra FATAL_MEM requirement, and
then uses xstrdup() in a few places (which would mean that strdup() is
being used for normal popt users).

I was also working on changing some code to use your newly-added
stpcpy() function, so I included that work too.  Some of the changes
are optimizations to avoid a strlen() call (when we can easily compute
the length via subtraction) and a fix for a potential memory leak if
realloc() returns NULL.

..wayne..


Received on Mon Mar 10 03:00:54 2008
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.