On Fri, 10 Feb 2012 18:11:20 +0100 Dr. Werner Fink wrote:
> Just a bug as in src/cmd/builtin/what.c line 133 and line 141
> a `s[3]' is touched.

thanks for pointing that out
that section of code is a hand rolled boyer-moore match on two 4 byte strings 
"@(#)" and "$Id:"
specifically the part that handles matches that span buffer boundaries
it was rife with errors from a sloppy cut and paste
here is the diff -u of the fix -- your line numbers will be off by ~20

@@ -102,7 +102,7 @@
                                switch (skip[buf[0]])
                                {
                                case HIT:
-                                       if (buf[0] == ')' && s[0] == '@' && 
s[1] == '(' && s[2] == '#' || buf[0] == ':' && s[0] == '$' && s[1] == 'I' && 
s[2] == 'd')
+                                       if (buf[0] == ')' && s[2] == '#' && 
s[1] == '(' && s[0] == '@' || buf[0] == ':' && s[2] == 'd' && s[1] == 'I' && 
s[0] == '$')
                                        {
                                                index = 0;
                                                s = buf + 1;
@@ -110,7 +110,7 @@
                                        }
                                        break;
                                case 1:
-                                       if (buf[0] == ')' && s[1] == '@' && 
s[2] == '(' && buf[1] == '#' || buf[0] == ':' && s[1] == '$' && s[2] == 'I' && 
s[3] == 'd')
+                                       if (buf[1] == ')' && buf[0] == '#' && 
s[2] == '(' && s[1] == '@' || buf[1] == ':' && buf[0] == 'd' && s[2] == 'I' && 
s[1] == '$')
                                        {
                                                index = 1;
                                                s = buf + 2;
@@ -118,7 +118,7 @@
                                        }
                                        break;
                                case 2:
-                                       if (buf[0] == ')' && s[2] == '@' && 
buf[1] == '(' && buf[2] == '#' || buf[0] == ':' && s[2] == '$' && s[3] == 'I' 
&& s[3] == 'd')
+                                       if (buf[2] == ')' && buf[1] == '#' && 
buf[0] == '(' && s[2] == '@' || buf[2] == ':' && buf[1] == 'd' && buf[0] == 'I' 
&& s[2] == '$')
                                        {
                                                index = 2;
                                                s = buf + 3;
@@ -176,7 +176,7 @@
                                                        list:
                                                                if ((s - b) > 2 
&& *(s - 1) == '$' && *(s - 2) == ' ')
                                                                        s -= 2;
-                                                               if (s > b)
+                                                               if (s > b || 
!*t)
                                                                {
                                                                        
sfprintf(op, "%s%-.*s\n", t, s - b, b);
                                                                        
state.hit = 1;

_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to