From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10154 invoked by alias); 20 Oct 2014 18:39:14 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 10132 invoked by uid 89); 20 Oct 2014 18:39:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.98.4 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-Spam-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com From: David Malcolm To: jit@gcc.gnu.org, gcc-patches@gcc.gnu.org, "Joseph S. Myers" Cc: David Malcolm Subject: [jit] Error-handling within gcc::jit::dump Date: Wed, 01 Jan 2014 00:00:00 -0000 Message-Id: <1413830100-9659-1-git-send-email-dmalcolm@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-SW-Source: 2014-q4/txt/msg00048.txt.bz2 On Fri, 2014-10-17 at 21:52 +0000, Joseph S. Myers wrote: [...snip static linkage discussion...] > The dump file handling appears to have no I/O error checking (no checking > for error on fopen, nothing obvious to prevent fwrite to a NULL m_file if > fopen did have an error, no checking for error on fclose (or fwrite)). Thanks. Does the following look OK? (I've committed it to branch dmalcolm/jit) gcc/jit/ChangeLog.jit: * jit-recording.c (gcc::jit::dump::dump): Handle fopen failures by emitting an error on the context. (gcc::jit::dump::~dump): Likewise for fclose failures. (gcc::jit::dump::write): Don't attempt further work if the fopen failed. Handle fwrite failures by emitting an error on the context. --- gcc/jit/ChangeLog.jit | 9 +++++++++ gcc/jit/jit-recording.c | 25 ++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit index 9a36dfd..02664f0 100644 --- a/gcc/jit/ChangeLog.jit +++ b/gcc/jit/ChangeLog.jit @@ -1,5 +1,14 @@ 2014-10-20 David Malcolm + * jit-recording.c (gcc::jit::dump::dump): Handle fopen failures + by emitting an error on the context. + (gcc::jit::dump::~dump): Likewise for fclose failures. + (gcc::jit::dump::write): Don't attempt further work if the fopen + failed. Handle fwrite failures by emitting an error on the + context. + +2014-10-20 David Malcolm + * Make-lang.in (jit.install-common): Drop installation of libgccjit.pc. * config-lang.in (outputs): Drop jit/libgccjit.pc. diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c index 32ce49b..5a97f23 100644 --- a/gcc/jit/jit-recording.c +++ b/gcc/jit/jit-recording.c @@ -47,13 +47,25 @@ dump::dump (recording::context &ctxt, m_line (0), m_column (0) { - m_file = fopen (filename, "w"); + m_file = fopen (filename, "w"); + if (!m_file) + ctxt.add_error (NULL, + "error opening dump file %s for writing: %s", + filename, + xstrerror (errno)); } dump::~dump () { if (m_file) - fclose (m_file); + { + int err = fclose (m_file); + if (err) + m_ctxt.add_error (NULL, + "error closing dump file %s: %s", + m_filename, + xstrerror (errno)); + } } /* Write the given message to the dump, using printf-formatting @@ -67,6 +79,11 @@ dump::write (const char *fmt, ...) va_list ap; char *buf = NULL; + /* If there was an error opening the file, we've already reported it. + Don't attempt further work. */ + if (!m_file) + return; + va_start (ap, fmt); vasprintf (&buf, fmt, ap); va_end (ap); @@ -78,7 +95,9 @@ dump::write (const char *fmt, ...) return; } - fwrite (buf, strlen (buf), 1, m_file); + if (fwrite (buf, strlen (buf), 1, m_file) != 1) + m_ctxt.add_error (NULL, "error writing to dump file %s", + m_filename); /* Update line/column: */ for (const char *ptr = buf; *ptr; ptr++) -- 1.7.11.7