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

Re: svn commit: r10143 - in trunk/subversion: libsvn_subr tests/libsvn_subr

From: Klaus Rennecke <kre_at_tigris.org>
Date: 2004-07-05 17:30:59 CEST

Greg Hudson wrote:

>On Mon, 2004-07-05 at 09:06, jpieper@tigris.org wrote:
>
>
>>[...]
>>+ while (path->len > 0 && path->data[path->len] != '/')
>>[...]
>>
>>
>
>The valid indices of path->data range from 0 to path->len - 1.[..]
>
>

I would like to suggest refactoring remove_component and dirname since
they both need the same logic. This will fix the index concern as well.

/Klaus

Index: D:/kre/workspace/svn/subversion/libsvn_subr/path.c
===================================================================
--- D:/kre/workspace/svn/subversion/libsvn_subr/path.c (revision 10142)
+++ D:/kre/workspace/svn/subversion/libsvn_subr/path.c (working copy)
@@ -264,6 +264,24 @@
 
 
 
+static apr_size_t
+previous_nonempty_segment (const char *path,
+ apr_size_t len)
+{
+ if (len == 0)
+ return 0;
+
+ while (len > 0 && path[--len] != '/')
+ ;
+
+ if (len == 0 && path[0] == '/')
+ return len + 1;
+ else if (SVN_PATH_IS_PLATFORM_EMPTY(path, len))
+ return 0;
+ else
+ return len;
+}
+
 void
 svn_path_add_component (svn_stringbuf_t *path,
                         const char *component)
@@ -291,13 +309,8 @@
 {
   assert (is_canonical (path->data, path->len));
 
- while (path->len > 0 && path->data[path->len - 1] != '/')
- --path->len;
-
+ path->len = previous_nonempty_segment(path->data, path->len);
   path->data[path->len] = '\0';
-
- if (SVN_PATH_IS_PLATFORM_EMPTY (path->data, path->len))
- svn_stringbuf_set (path, SVN_EMPTY_PATH);
 }
 
 
@@ -308,16 +321,7 @@
 
   assert (is_canonical (path, len));
 
- while (len > 0 && path[len] != '/')
- --len;
-
- if (len == 0 && path[0] == '/')
- ++len;
-
- if (SVN_PATH_IS_PLATFORM_EMPTY (path, len))
- return apr_pmemdup (pool, SVN_EMPTY_PATH, sizeof (SVN_EMPTY_PATH));
-
- return apr_pstrmemdup (pool, path, len);
+ return apr_pstrmemdup (pool, path, previous_nonempty_segment(path, len));
 }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Jul 5 17:32:10 2004

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