[cups.general] Fwd: CUPS STR #1036 updated
Michael Sweet
mike at easysw.com
Tue Dec 28 11:49:42 PST 2004
Marc Balmer wrote:
> ...
> You are wrong in assuming that this is a compiler only warning. Your
> code behaves different on plattforms where char is unsigned (like
> macppc/OpenBSD).
We have access to systems that use both signed and unsigned chars
by default, and neither type of platform has a problem with the
code.
The type of check you references in STR #1036 was:
if ((*ptr >= 0 && *ptr <= ' ') || *ptr == 127 || *ptr == '/')
On a system that has unsigned characters, this reduces to:
if ((1 && *ptr <= ' ') || *ptr == 127 || *ptr == '/')
or just:
if (*ptr <= ' ' || *ptr == 127 || *ptr == '/')
Since we are checking that the user has supplied an 8-bit character
between SP (32) and 255, excluding "/" (47) and DEL (127). The test
we use is therefore valid regardless of the signedness of the char
type on a particular platform.
If you don't like getting the (nonsense) compiler warning in your
compiles, then patch the version of CUPS you ship with OpenBSD -
you already have stated there are other changes that are OpenBSD
specific anyways...
> If you do not want to use signed char * then you have to rewrite the
> test. On platforms with unsigned chars the first test (*ptr >= 0) is
> always true.
So what? The test is harmless, and a compiler that says "foo is
always true) will probably optimize it away anyways...
> You really should not trade convenience for buggy code....
The code is not buggy, it has been written specifically to work
for both signed and unsigned char types without changes.
--
______________________________________________________________________
Michael Sweet, Easy Software Products mike at easysw dot com
Internet Printing and Publishing Software http://www.easysw.com
More information about the cups
mailing list