[ovs-dev] [PATCH] bridge: Modify equal_pathnames function

Ben Pfaff blp at nicira.com
Wed Jan 23 21:29:49 UTC 2013


On Wed, Jan 23, 2013 at 01:22:03PM -0800, Pavithra Ramesh wrote:
> Modify equal_pathnames to return true when one string is
> substring of the other(when a value smaller than SIZE_MAX
> is supplied as stop_len)

I think this change is correct only when b_stoplen == strlen(b).
That's the case for the current caller but it's supposed to be more
general.

How about this:

diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 82c3bff..dd3099f 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -2740,8 +2740,12 @@ static bool
 equal_pathnames(const char *a, const char *b, size_t b_stoplen)
 {
     const char *b_start = b;
-    while (b - b_start < b_stoplen && *a == *b) {
-        if (*a == '/') {
+    for (;;) {
+        if (b - b_start >= b_stoplen) {
+            return true;
+        } else if (*a != *b) {
+            return false;
+        } else if (*a == '/') {
             a += strspn(a, "/");
             b += strspn(b, "/");
         } else if (*a == '\0') {
@@ -2751,7 +2755,6 @@ equal_pathnames(const char *a, const char *b, size_t b_stoplen)
             b++;
         }
     }
-    return false;
 }
 
 static void



More information about the dev mailing list