Path: utzoo!mnetor!uunet!mcvax!unido!sbsvax!greim From: greim@sbsvax.UUCP (Michael Greim) Newsgroups: comp.bugs.4bsd Subject: Re: C-shell expression bug with fix. My fix. Message-ID: <469@sbsvax.UUCP> Date: 23 Mar 88 14:36:49 GMT Organization: Universitaet des Saarlandes, D-6600 Saarbruecken, FRG Lines: 121 Keywords: csh expression pattern bug Hi folks, Sorry that I am a little late with this fix, but our computers got moved to a new building, so we were rather isolated the last few days. In <479@sol.warwick.ac.uk> Rob McMahon writes : >One of our students reported the following bug to me: > > % if ( abc =~ * ) echo yes > > % if ( abc =~ ** ) echo yes > yes > > Further investigation gave the following: > > % if ( 0 =~ * ) echo yes > yes > % if ( 2 == 2 + ) echo yes > yes > % if ( 2 == + 2 ) echo yes > yes > > The * is being treated as multiply, and the shell doesn't care that it's > got no operands, it just fills them in with 0. I've applied the > following fix, but I'm slightly unsure about it because I may have Well the fix causes some new bugs. I present here my own fix, which seems to work slightly better. I append a file I used for testing which demonstrates the use of patterns. I don't think it should be an error if you tried if ( 2 == 2 + ) echo yes because the manual explicitly says : "... Null or missing arguments are considered '0'" so my fix only fixes the behaviour when dealing with a pattern. FIX: *** sh.exp.c.old Wed Mar 23 14:29:26 1988 --- sh.exp.c Wed Mar 23 14:27:53 1988 *************** *** 156,164 **** #endif if (i = isa(**vp, EQOP)) { (*vp)++; ! if (i == EQMATCH || i == NOTEQMATCH) ignore |= NOGLOB; ! p2 = exp3(vp, ignore); #ifdef EDEBUG etracc("exp2c p2", p2, vp); #endif --- 156,167 ---- #endif if (i = isa(**vp, EQOP)) { (*vp)++; ! if (i == EQMATCH || i == NOTEQMATCH) { ignore |= NOGLOB; ! p2 = **vp; ! (*vp)++; ! } else ! p2 = exp3(vp, ignore); #ifdef EDEBUG etracc("exp2c p2", p2, vp); #endif TESTS: if ( abc =~ * ) then echo "ok 1" else echo "false 1" endif if ( "abc" =~ * ) then echo "ok 2" else echo "false 2" endif set abc='d b' if ( "$abc" =~ d\ * ) then echo "ok 3" else echo "false 3" endif set abc='234 - zzz' if ( "$abc" =~ [1-9]*\ -\ ??? ) then echo "ok 4" else echo "false 4" endif set abc='"abc"' if ( $abc =~ \"*\" ) then echo "ok 5" else echo "false 5" endif set abc='misty?hallo' set def='call.me' if ( $abc =~ *\?* && $def !~ *\?me ) then echo "ok 6" else echo "false 6" endif Running this file through old csh should produce : false 1 false 2 ok 3 ok 4 ok 5 misty?hallo: no match Running cured csh returns for all cases "ok". Have a nice day, Michael