C-shell expression bug with fix. My fix.
Michael Greim
greim at sbsvax.UUCP
Thu Mar 24 00:36:49 AEST 1988
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 at sol.warwick.ac.uk> Rob McMahon writes :
>One of our students reported the following bug to me:
>
> % if ( abc =~ * ) echo yes
> <silence>
> % 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
<rest deleted>
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
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list