bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xstrdup (NULL)


From: Bruno Haible
Subject: Re: xstrdup (NULL)
Date: Sat, 20 Oct 2007 22:56:08 +0200
User-agent: KMail/1.5.4

Hi,

Colin Watson wrote:
> The hand-rolled implementation of xstrdup I used to use before
> converting to Gnulib tolerated being passed a NULL string and simply
> returned NULL. I found this convenient; it saved a number of tedious
> checks, in much the same way that free doesn't mind being passed a NULL
> pointer. Would you consider this patch?

We already discussed this in [1]:

"For the developer it's easier to remember if the 'x' stands for just
 one thing: checking the memory allocation failures. xmalloc, xstrdup,
 xgethostname, xgetcwd, xsetenv, etc. have this in common.

 strdup(NULL) is an error, therefore xstrdup(NULL) should continue to be
 banned as well."

Yes, on one hand, there are many places where one writes
  (string != NULL ? xstrdup (string) : NULL)

On the other hand, there are also many places where one expects a non-NULL
string, and I'm glad that xstrdup guarantees a non-NULL result, because
this means I can stop searching whether the value could possibly be NULL
or not.

Bruno

[1] http://lists.gnu.org/archive/html/bug-gnulib/2004-02/msg00026.html





reply via email to

[Prev in Thread] Current Thread [Next in Thread]