bug-m4
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: HEAD: inclusion order wrong for input.c


From: Eric Blake
Subject: Re: HEAD: inclusion order wrong for input.c
Date: Mon, 2 Apr 2007 20:14:46 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Matthew Woehlke <mw_triad <at> users.sourceforge.net> writes:

> 
> (WCTS) ...an explicit typecast to int doesn't solve this? Seems to work 
> here:
> 
> $ gcc -Wall -Wextra -o aci arrayci.c
> arrayci.c: In function `main':
> arrayci.c:7: warning: array subscript has type `char'
> $ gcc -Wall -Wextra -DCAST='(int)(unsigned)' -o aci arrayci.c
> $ cat arrayci.c
> #ifndef CAST
> #define CAST
> #endif
> int main() {
>          char c = 'q';
>          char foo[256] = { 0 };
>          return foo[CAST c];
> }

That's buggy.  char can be signed, so promoting char to int,
whether or not by an explicit cast to int, means that you may
be derefencing negative indices into the array.  The correct
fix is to cast to unsigned char (or, in the m4 source code, use
the to_uchar inline function, which has better type safety).

I'll be submitting a patch for these issues shortly.

-- 
Eric Blake






reply via email to

[Prev in Thread] Current Thread [Next in Thread]