[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_fs id.c

From: Greg Stein <gstein_at_lyra.org>
Date: 2001-03-30 01:44:00 CEST

On Thu, Mar 29, 2001 at 11:30:19PM -0000, cmpilato@tigris.org wrote:
>...
> --- id.c 2001/03/23 20:24:16 1.18
> +++ id.c 2001/03/29 23:30:18 1.19
> @@ -122,10 +122,11 @@
> return -1;
>
> /* Skip any common prefix. */
> - for (i = 0; a[i] == b[i] && a[i+1] == b[i+1]; i += 2)
> - /* If they're completely identical, then the distance is zero. */
> - if (a[i] == -1)
> - return 0;
> + for (i = 0; a[i] == b[i] && a[i+1] == b[i+1] && a[i] != -1; i+=2);

For constructs like above, I tend to write them like:

  for (init; test; next)
    continue;

That shows the readers that you *intended* to have a no-op loop. In the
above case, somebody might go "where's the body?" or "whoops! they put a
semicolon after the for-loop!"

Second, the construct is incorrect. You should test for a[i] != -1 *first*.
Assume that a[i] == b[i] == -1, then the above check will test a[i+1] which
is *past* the end of the ID.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/
Received on Sat Oct 21 14:36:26 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.