[Top][All Lists]

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

Re: [Bug-gnulib] xalloc: add xstrndup

From: Simon Josefsson
Subject: Re: [Bug-gnulib] xalloc: add xstrndup
Date: Fri, 15 Aug 2003 05:36:25 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Paul Eggert <address@hidden> writes:

>> +  /* FIXME we may allocate more than needed amount. however strlen()
>> +     may read out of bounds in case string is not zero terminated.
>> +     looping through string (limited by n) waste cpu, this waste
>> +     memory. */
> Why not do something like this instead?
>         char *s = strndup (string, n);
>         if (! s)
>           xalloc_die ();
>       return s;

Better, thanks.  (I hadn't noticed the xalloc_die() function.)

reply via email to

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