The ctype functions take int arguments, which may have the value of any char and additionally EOF, like the return value of getc(3). On architectures like x86 where char is signed by default, passing a char to an int parameter will sign-extend the value. In particular, a char with value 0xff will turn into 0xffffffff, which is -1, which is typically the value of EOF. Confusion results between 0xff and EOF.
To prevent this problem cast arguments to (unsigned char) in all calls to isspace(), tolower(), isxdigit(), isdigit(), and isprint(), as done all over the OpenBSD base source tree nowadays. There are a few cases where the argument is already unsigned but those re now also cast for cosmetic reasons. There were no cases where the argument was already of type int which would make casting unnecessary.
Also:
Replace some use of non-standard u_char with unsigned char, in order to make ctype-usage bulk-reviews easier in combination with 'grep'.
Remove pointless LOWER() macro which just re-implements an isupper() check which tolower() is already doing internally.
The ctype functions take int arguments, which may have the value of any char and additionally EOF, like the return value of getc(3). On architectures like x86 where char is signed by default, passing a char to an int parameter will sign-extend the value. In particular, a char with value 0xff will turn into 0xffffffff, which is -1, which is typically the value of EOF. Confusion results between 0xff and EOF.
To prevent this problem cast arguments to (unsigned char) in all calls to isspace(), tolower(), isxdigit(), isdigit(), and isprint(), as done all over the OpenBSD base source tree nowadays. There are a few cases where the argument is already unsigned but those re now also cast for cosmetic reasons. There were no cases where the argument was already of type int which would make casting unnecessary.
Also:
Replace some use of non-standard u_char with unsigned char, in order to make ctype-usage bulk-reviews easier in combination with 'grep'.
Remove pointless LOWER() macro which just re-implements an isupper() check which tolower() is already doing internally.