From 60743b3b4cdebbea3600c12d6221d4726e44040b Mon Sep 17 00:00:00 2001 From: oes Date: Tue, 12 Nov 2002 14:30:04 +0000 Subject: [PATCH] Proper backtracking in simplematch; fixes bug #632888 --- src/miscutil.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/miscutil.c b/src/miscutil.c index 0779c1aa..77489135 100644 --- a/src/miscutil.c +++ b/src/miscutil.c @@ -1,7 +1,7 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 2.2 2002/08/26 11:16:33 sarantis Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 2.3 2002/09/25 13:00:41 oes Exp $"; /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/src/miscutil.c,v $ + * File : $Source: /cvsroot/ijbswa//current/src/miscutil.c,v $ * * Purpose : zalloc, hash_string, safe_strerror, strcmpic, * strncmpic, chomp, and MinGW32 strdup @@ -36,6 +36,10 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 2.2 2002/08/26 11:16:33 sarantis * * Revisions : * $Log: miscutil.c,v $ + * Revision 2.3 2002/09/25 13:00:41 oes + * Made strcmpic and strncmpic safe against NULL arguments + * (which are now treated as empty strings). + * * Revision 2.2 2002/08/26 11:16:33 sarantis * Fix typo. * @@ -826,25 +830,28 @@ int simplematch(char *pattern, char *text) if ((*pat == *txt) || ((*pat == ']') && (charmap[*txt / 8] & (1 << (*txt % 8)))) ) { - /* Sucess, go ahead */ + /* + * Sucess: Go ahead + */ pat++; } - else + else if (!wildcard) { - /* In wildcard mode, just try again after failure */ - if(wildcard) - { - pat = fallback; - } - - /* Else, bad luck */ - else - { - return 1; - } + /* + * No match && no wildcard: No luck + */ + return 1; + } + else if (pat != fallback) + { + /* + * Wildcard mode && nonmatch beyond fallback: Rewind pattern + */ + pat = fallback; + continue; } txt++; - } + } /* Cut off extra '*'s */ if(*pat == '*') pat++; -- 2.39.2