Path: utzoo!utgpu!cs.utexas.edu!uunet!munnari.oz.au!uniwa!DIALix!bernie From: bernie@DIALix.oz.au (Bernd Felsche) Newsgroups: alt.sources.d Subject: wildmat BUG and Fix (was Re: Revised C filename wildcard routine) Message-ID: <709@DIALix.oz.au> Date: 4 Jan 91 14:06:44 GMT References: <3154@litchi.bbn.com> Organization: DIALix Services, Perth Western Australia Lines: 49 In <3154@litchi.bbn.com> rsalz@bbn.com (Rich Salz) writes: >This is a revised version of my pattern-matching routine. It has been >posted to the net several times, and shows up in several places including >Gilmore's public domain TAR. You might want to test this, but I did >and it seems solid. It's neat, and arrived at our site on the very day it was needed. :-) It's not quite solid enough, though. It won't match string "ab" to pattern "ab*" A trailing "*" never matches a trailing (null) string. The BUG is: [... start of shar deleted ...] >Xstatic int >XDoMatch(s, p) >X register char *s; >X register char *p; >X{ >X register int last; >X register int matched; >X register int reverse; >X >X for ( ; *p; s++, p++) { >X if (*s == '\0') >X return ABORT; [ ... rest of shar deleted ... ] The FIX: return ABORT; becomes: return *p == '*' && *++p == '\0' ? TRUE : ABORT; This is not the way I usually write code, but it blends in with the style of the rest of the code. :-) You probably won't be able to tell that it's a patch. What the package really needs, is a syntax parser (to check for closing ], and for ][ inside character ranges) and a compressor (for things like "**"). This would stop it rampaging through memory until it hits an MMU boundary. How does this code compare with "bash"? Anybody familiar enough with bash to excise the filename expansion stuff from that? -- ________Bernd_Felsche__________bernie@DIALix.oz.au_____________ [ Phone: +61 9 419 2297 19 Coleman Road ] [ TZ: UTC-8 Calista, Western Australia 6167 ]