From: Marko Kreen Date: Fri, 13 Apr 2007 11:30:24 +0000 (+0000) Subject: strlist_contains should loop on failed compare, not exit X-Git-Tag: pgbouncer_1_0_7~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a092a0777b82d7e6fdfa51597e15644f60c86617;p=pgbouncer strlist_contains should loop on failed compare, not exit --- diff --git a/src/util.c b/src/util.c index 2eb342e..6f83421 100644 --- a/src/util.c +++ b/src/util.c @@ -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; }