You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by kf...@collab.net on 2001/08/14 16:06:28 UTC

Re: CVS update: MODIFIED: libsvn_ra_dav ...

gstein@tigris.org writes:
>   +
>   +  /* use custom prefix for anything that doesn't start with "svn:" */
>   +  if (strncmp(name, "svn:", 4) == 0)
>   +    ne_buffer_concat(body, "<S:", name + 4, ">", value, "</S:", name + 4, ">",
>   +                     NULL);
>   +  else
>   +    ne_buffer_concat(body, "<C:", name, ">", value, "</C:", name, ">", NULL);
>   +
>      return 1;
>    }

Greg, should we worry about the case where name < 4 bytes long?  It
seems to me the strncmp() might run off the end, then.

>   +          const char *name = APR_ARRAY_IDX(rb->prop_deletes, n, const char *);
>   +
>   +          /* use custom prefix for anything that doesn't start with "svn:" */
>   +          if (strncmp(name, "svn:", 4) == 0)
>   +            ne_buffer_concat(body, "<S:", name + 4, "/>", NULL);
>   +          else
>   +            ne_buffer_concat(body, "<C:", name, "/>", NULL);
>            }

Same question here, of course.

?,
-K

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: CVS update: MODIFIED: libsvn_ra_dav ...

Posted by kf...@collab.net.
Joe Orton <jo...@manyfish.co.uk> writes:
> Are you thinking strncmp compares exactly 4 bytes? It compares *at most*
> 4 bytes, and still terminates on a \0 before that...

Yeah, I was thinking the former.  

Now, I want it on the record that this possibility *did* occur to me
before I wrote Greg :-) ... So I went and looked it up.  The combined
manual entry for strcmp() and strncmp() on my system says:

   The  strcmp() function compares the two strings s1 and s2.
   It returns an integer less than, equal to, or greater than
   zero  if  s1  is  found, respectively, to be less than, to
   match, or be greater than s2.
   
   The strncmp() function is similar, except it only compares
   the first n characters of s1.

Which is at best ambiguous.  I just went and looked it up in K&R.
They get it right, by inserting an "at most" before "the first".

Thanks for the reminder, Joe!

-K

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: CVS update: MODIFIED: libsvn_ra_dav ...

Posted by Joe Orton <jo...@manyfish.co.uk>.
On Tue, Aug 14, 2001 at 11:06:28AM -0500, Karl Fogel wrote:
> >   +  /* use custom prefix for anything that doesn't start with "svn:" */
> >   +  if (strncmp(name, "svn:", 4) == 0)
> Greg, should we worry about the case where name < 4 bytes long?  It
> seems to me the strncmp() might run off the end, then.

Are you thinking strncmp compares exactly 4 bytes? It compares *at most*
4 bytes, and still terminates on a \0 before that...

joe

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: CVS update: MODIFIED: libsvn_ra_dav ...

Posted by Greg Stein <gs...@lyra.org>.
On Tue, Aug 14, 2001 at 11:06:28AM -0500, kfogel@collab.net wrote:
> gstein@tigris.org writes:
> >   +
> >   +  /* use custom prefix for anything that doesn't start with "svn:" */
> >   +  if (strncmp(name, "svn:", 4) == 0)
> >   +    ne_buffer_concat(body, "<S:", name + 4, ">", value, "</S:", name + 4, ">",
> >   +                     NULL);
> >   +  else
> >   +    ne_buffer_concat(body, "<C:", name, ">", value, "</C:", name, ">", NULL);
> >   +
> >      return 1;
> >    }
> 
> Greg, should we worry about the case where name < 4 bytes long?  It
> seems to me the strncmp() might run off the end, then.

memcmp() does an exact amount.

strncmp() does "at most" N characters. It will terminate if '\0' is reached
beforehand.

And yes, I'm worried about a name such as "hi" when somebody goes to test
the thing out.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org