Re: Goto?!? (was Re: A89: fwrite bug located (and a bugfix))
[Prev][Next][Index][Thread]
Re: Goto?!? (was Re: A89: fwrite bug located (and a bugfix))
Hi!
> Since I was bored... I decided to find out. Btw, doesn't
> casting of a signed number to a unsigned number cause bad
> things?
You are right. My bugfix for fwrite is correct, the following
code is not problematic (note that fnc returns signed int):
if(fnc(*(unsigned char*)ptr++,f)<0) goto exit;
But, the "fixed" version of fread given by Michael is not
correct. It contains an incorrect statement
if((*(unsigned char*)ptr++=fgetc(f))<0) goto exit;
due to the fact that the comparison will always be false
(unsigned can't be less than zero).
As far as I can see, fread in fact does not need any
fixing at all!!! The original statement was
if((*(char*)ptr++=fgetc(f))<0) goto exit;
and I can't see any problems with it... Nothing is wrong
with storing "negative" chars in the memory...
Zeljko
Follow-Ups: