]> granicus.if.org Git - pgbouncer/commitdiff
strlist_contains should loop on failed compare, not exit
authorMarko Kreen <markokr@gmail.com>
Fri, 13 Apr 2007 11:30:24 +0000 (11:30 +0000)
committerMarko Kreen <markokr@gmail.com>
Fri, 13 Apr 2007 11:30:24 +0000 (11:30 +0000)
src/util.c

index 2eb342ea2601f7010cbca874ad39defa0ab865e6..6f83421baa9df63c474d58d67aa073ea19427c56 100644 (file)
@@ -543,26 +543,39 @@ void tune_socket(int sock, bool is_unix)
                fatal_perror("setsockopt TCP_NODELAY");
 }
 
-
+/*
+ * Find a string in comma-separated list.
+ *
+ * It does not support space inside tokens.
+ */
 bool strlist_contains(const char *liststr, const char *str)
 {
        int c, len = strlen(str);
-       const char *p = strstr(liststr, str);
-
+       const char *p, *listpos = liststr;
+       
+loop:
+       /* find string fragment, later check if actual token */
+       p = strstr(listpos, str);
        if (p == NULL)
                return false;
 
-       /* check if item start */
+       /* move listpos further */
+       listpos = p + len;
+       /* survive len=0 and avoid unneccesary compare */
+       if (*listpos)
+               listpos++;
+
+       /* check previous symbol */
        if (p > liststr) {
                c = *(p - 1);
                if (!isspace(c) && c != ',')
-                       return false;
+                       goto loop;
        }
 
-       /* check if item end */
+       /* check following symbol */
        c = p[len];
        if (c != 0 && !isspace(c) && c != ',')
-               return false;
+               goto loop;
 
        return true;
 }