This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: GCC char* bug


Geoff Keating wrote:

> I'm not sure what code precisely you're reporting a bug about,

gcc/fixinc/fixincl.c

> but if you write
> 
> char pz_cmp_star = -10;
> int ch;
> 
> ch = getc (in_fp);
> ch &= 0xFF;
> if (ch != pz_cmp_star)
>   abort();
> 
> you will always hit the abort() since '(int)x & 0xFF' is never
> going to be -10.

Of course it won't.  Sorry, I inserted the fix into the sample
code.  The problem is this:

  char ch = 0xF6;
  FILE* fp = fopen( "test", "w+" );
  int inch;
  fputc( ch, fp );
  rewind( fp );
  inch = fgetc( fp );
  if (ch != inch)
    abort();

This should _never_ abort on a platform where libc and
the compiler agree on the sign-ed-ness of char.  It
aborts on Linux with GCC.  My claim is that that is wrong.
Either getc/fgetc needs fixing, or GCC does.  Either way.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]