cvs commit: src/lib/libfetch fetch.c ftp.c http.c
Ruslan Ermilov
ru at freebsd.org
Tue Dec 18 05:08:18 PST 2007
On Tue, Dec 18, 2007 at 10:41:12AM +0000, Dag-Erling Smorgrav wrote:
> des 2007-12-18 10:41:12 UTC
>
> FreeBSD src repository
>
> Modified files:
> lib/libfetch fetch.c ftp.c http.c
> Log:
> Old patch I had lying around: correctly cast the argument to is*().
> IWBNI gcc could warn about this the way it warns about printf() abuse.
>
> MFC after: 1 week
>
> Revision Changes Path
> 1.40 +2 -2 src/lib/libfetch/fetch.c
> 1.98 +10 -10 src/lib/libfetch/ftp.c
> 1.80 +13 -12 src/lib/libfetch/http.c
>
These casts are bogus. is*() expect a value that's representable
as either "unsigned char" or EOF, so the correct fix would be to
either make underlying types "unsigned char" instead of "char",
or cast an argument to "unsigned char".
: #include <stdio.h>
:
: void
: foo(int x)
: {
:
: printf("%d\n", x);
: }
:
: int
: main(void)
: {
: char c;
: unsigned char uc;
:
: foo(EOF); /* will be printed as -1 */
:
: c = 0xff;
: foo(c); /* bug */
: foo((int)c); /* bug (cast is a no-op) */
: foo((unsigned char)c); /* good cast */
:
: uc = 0xff;
: foo(uc); /* ok */
: foo((int)uc); /* ok (no-op cast) */
:
: return (0);
: }
Cheers,
--
Ruslan Ermilov
ru at FreeBSD.org
FreeBSD committer
More information about the cvs-src
mailing list