You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Greg Stein <gs...@lyra.org> on 2001/03/29 23:44:00 UTC

Re: CVS update: subversion/subversion/libsvn_fs id.c

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/