[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.)
- [Bug-gnulib] xalloc: add xstrndup, Simon Josefsson, 2003/08/14
- Re: [Bug-gnulib] xalloc: add xstrndup, Paul Eggert, 2003/08/14
- Re: [Bug-gnulib] xalloc: add xstrndup,
Simon Josefsson <=
- Re: [Bug-gnulib] xalloc: add xstrndup, Bruno Haible, 2003/08/15
- Re: [Bug-gnulib] xalloc: add xstrndup, Paul Eggert, 2003/08/15
- Re: [Bug-gnulib] xalloc: add xstrndup, Simon Josefsson, 2003/08/15
- Re: [Bug-gnulib] xalloc: add xstrndup, Bruno Haible, 2003/08/17
- Re: [Bug-gnulib] xalloc: add xstrndup, Simon Josefsson, 2003/08/17
- Re: [Bug-gnulib] xalloc: add xstrndup, Bruno Haible, 2003/08/18
- Re: [Bug-gnulib] xalloc: add xstrndup, Paul Eggert, 2003/08/18
- Re: [Bug-gnulib] xalloc: add xstrndup, Derek Robert Price, 2003/08/22
- Re: [Bug-gnulib] xalloc: add xstrndup, Bruno Haible, 2003/08/22