apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Pane <bp...@pacbell.net>
Subject Re: apr_pstrndup
Date Wed, 28 Nov 2001 07:55:57 GMT
Doug MacEachern wrote:

>does this:
>    end = memchr(s, '\0', n);
>    if (end != NULL)
>        n = end - s;
>
>is that just  to avoid allocating an extra byte if 's' already contains
>'\0' at the end?  seem like it would be better to waste the extra byte
>than to scan the whole string with memchr() or at least change that to:
>    if (*(s + (n-1)) == '\0') {
>        n--;
>    }
>

There's no guarantee that strlen(s) is anywhere near n.  It's valid
for a caller to do this, for example:
  apr_pstrndup(p, "foo", 65536);

--Brian




Mime
View raw message