YUCK!
I went to considerable effort to avoid that sort of access_iostream() junk.
Foo!
Barf. Oh well.
On Sun, Nov 16, 2008 at 9:12 PM, Aleksi Nurmi <[EMAIL PROTECTED]>wrote:
> 2008/11/17 Aleksi Nurmi <[EMAIL PROTECTED]>:
> >> I was unable to reproduce this bug. How are you running it?
> >
> > I'm sorry to hear that. Sometimes I'm unable to reproduce it myself.
> > Let's hope there aren't any obscure memory corrupting pointers!
>
> Ha, found it - a likely GCC (4.2.4-1ubuntu3) bug! I guess the
> optimizer assumes that stdin is constant or something. The following
> code segfaults if access_iostream is defined as inline and the -O2
> optimization is turned on. A quick fix would be to remove the inline
> keyword from the function fix_stdio_stream - might be necessary as
> there are probably quite a few GCC 4.2s around even in the near
> future.
>
> #include <stdio.h>
>
> struct iostream {
> FILE *f;
> };
>
> static struct iostream our_stdin = { 0 };
>
> inline void access_iostream(struct iostream* ios)
> {
> if (ios->f == 0)
> if (ios == &our_stdin)
> ios->f = stdin;
> }
>
> void read_char(struct iostream* ios)
> {
> access_iostream(ios);
> fgetc(ios->f);
> }
>
> int main()
> {
> read_char(&our_stdin);
>
> return 0;
> }
>
> Aleksi Nurmi
> _______________________________________________
> bitc-dev mailing list
> [email protected]
> http://www.coyotos.org/mailman/listinfo/bitc-dev
>
>
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev