public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "aleksi dot nurmi at helsinki dot fi" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/38167] New: Inline accessor to stdin is breaks on -O2 optimization Date: Mon, 17 Nov 2008 02:00:00 -0000 [thread overview] Message-ID: <bug-38167-16956@http.gcc.gnu.org/bugzilla/> (raw) It appears that the following inline accessor function to stdin doesn't do it's job if -O2 optimization is turned on, thus letting a null pointer pass and causing a segfault. This doesn't happen if the function is not declared inline. Version: gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3) Command line: gcc -O2 -o fault fault.c GNU libc 2.7 is known for its non-constant stdin and is probably required to actually get a segfault. Code in readable format: #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; } -- Summary: Inline accessor to stdin is breaks on -O2 optimization Product: gcc Version: 4.2.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: aleksi dot nurmi at helsinki dot fi GCC host triplet: x86_64-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38167
next reply other threads:[~2008-11-17 2:00 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-11-17 2:00 aleksi dot nurmi at helsinki dot fi [this message] 2008-11-17 2:03 ` [Bug c/38167] " aleksi dot nurmi at helsinki dot fi 2008-11-17 8:47 ` jakub at gcc dot gnu dot org 2008-11-17 14:08 ` aleksi dot nurmi at helsinki dot fi 2008-11-17 15:12 ` [Bug c/38167] Accessor " aleksi dot nurmi at helsinki dot fi 2008-11-17 15:55 ` [Bug c/38167] Accessor to stdin " aleksi dot nurmi at helsinki dot fi 2008-11-24 17:48 ` [Bug middle-end/38167] " pinskia at gcc dot gnu dot org 2008-11-24 18:19 ` aleksi dot nurmi at helsinki dot fi 2008-11-24 19:34 ` [Bug middle-end/38167] [4.2 Regression] " pinskia at gcc dot gnu dot org 2009-03-31 15:51 ` jsm28 at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-38167-16956@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).