Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Dec 2007 16:08:04 +0300
From:      Ruslan Ermilov <ru@freebsd.org>
To:        Dag-Erling Smorgrav <des@freebsd.org>
Cc:        cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org
Subject:   Re: cvs commit: src/lib/libfetch fetch.c ftp.c http.c
Message-ID:  <20071218130804.GA3211@team.vega.ru>
In-Reply-To: <200712181041.lBIAfCSk011869@repoman.freebsd.org>
References:  <200712181041.lBIAfCSk011869@repoman.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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@FreeBSD.org
FreeBSD committer



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071218130804.GA3211>