"regexp.h" does an incorrect comparison of a "char" against 255
Guy Harris
guy at sun.uucp
Wed Mar 26 15:04:49 AEST 1986
"regexp.h" compares a "char" expression against 255. On a machine with
8-bit signed "char"s and a correct C compiler, this comparison will always
indicate that the value of the expression is not equal to 255. What it
intended to do was mask the character with 0377 and then do the comparison.
Here's a context diff of the fix, with two free "lint" fixes courtesy of Doug
Gwyn:
*** /archbeluga/s5r2/usr/include/regexp.h Sat Nov 5 09:42:54 1983
--- /tmp/regexp.h Tue Mar 25 20:59:36 1986
***************
*** 220,225
*ep++ = c;
}
}
}
step(p1, p2)
--- 220,226 -----
*ep++ = c;
}
}
+ /*NOTREACHED*/
}
step(p1, p2)
***************
*** 400,405
}
}
}
static
--- 401,407 -----
}
}
+ /*NOTREACHED*/
}
static
***************
*** 406,411
getrnge(str)
register char *str;
{
low = *str++ & 0377;
size = (*str == 255)? 20000: (*str &0377) - low;
}
--- 408,415 -----
getrnge(str)
register char *str;
{
+ register int sizecode;
+
low = *str++ & 0377;
sizecode = *str & 0377;
if (sizecode == 255)
***************
*** 407,411
register char *str;
{
low = *str++ & 0377;
! size = (*str == 255)? 20000: (*str &0377) - low;
}
--- 411,419 -----
register int sizecode;
low = *str++ & 0377;
! sizecode = *str & 0377;
! if (sizecode == 255)
! size = 20000;
! else
! size = sizecode - low;
}
--
Guy Harris
{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
guy at sun.arpa (yes, really)
More information about the Net.bugs.usg
mailing list