[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: CVS update: subversion/subversion/libsvn_string svn_string.c

From: Greg Stein <gstein_at_lyra.org>
Date: 2000-08-18 10:22:50 CEST

On Fri, Aug 18, 2000 at 01:28:18AM -0000, kfogel@tigris.org wrote:
>...
> + /* Null termination is the convention -- even if we suspect the data
> + to be binary, it's not up to us to decide, it's the caller's
> + call. Heck, that's why they call it the caller! */
> + new_string->data[new_string->len + 1] = '\0';

One too far? i.e. drop the +1?

>...
> + str->data[str->len + 1] = '\0'; /* We don't know if this is binary
> + data or not, but convention is
> + to null-terminate. */

Is the buffer large enough? And the +1 should probably disappear.

>...
> svn_string_2cstring (const svn_string_t *str, apr_pool_t *pool)
> {
> /* allocate memory for C string, +1 for \0 */
> - size_t size = str->len + 1;
> - char *cstring = apr_palloc (pool, size);
> + char *cstring = apr_palloc (pool, (str->len + 1));
>
> /* copy bytes over */
> memcpy (cstring, str->data, str->len);
>
> /* add the trailing NULL */
> - cstring[size - 1] = 0;
> + cstring[str->len] = '\0';
>
> return cstring;
> }

If this does a memcpy() for one extra byte, then you'll get the null-term
that we always place into the buffer. (and not need to place it manually)

Note that 2cstring is somewhat bogus since a caller can just use str->data.
This function is probably better named as dup2cstring().

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/
Received on Sat Oct 21 14:36:07 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.