From: Jürg Billeter Date: Sun, 7 Feb 2010 10:23:48 +0000 (+0100) Subject: Fix crash when opening file fails X-Git-Tag: 0.8.0~299 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3587d178d7f612de8862ef23d3ab8e464aea4e16;p=thirdparty%2Fvala.git Fix crash when opening file fails Based on patch by pancake, fixes bug 606837. --- diff --git a/ccode/valaccodewriter.vala b/ccode/valaccodewriter.vala index ff0677bce..f2ddb7e38 100644 --- a/ccode/valaccodewriter.vala +++ b/ccode/valaccodewriter.vala @@ -51,7 +51,7 @@ public class Vala.CCodeWriter { private string temp_filename; private bool file_exists; - private FileStream stream; + private FileStream? stream; private int indent; private int current_line_number = 1; @@ -80,6 +80,10 @@ public class Vala.CCodeWriter { stream = FileStream.open (filename, "w"); } + if (stream == null) { + return false; + } + write_string ("/* %s generated by valac, the Vala compiler".printf (Path.get_basename (filename))); // Write the file name if known @@ -92,7 +96,7 @@ public class Vala.CCodeWriter { write_newline (); write_newline (); - return (stream != null); + return true; } /** diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index ae358fc9f..837481250 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -369,6 +369,10 @@ internal class Vala.CCodeBaseModule : CCodeModule { // generate symbols file for public API if (context.symbols_filename != null) { var stream = FileStream.open (context.symbols_filename, "w"); + if (stream == null) { + Report.error (null, "unable to open `%s' for writing".printf (context.symbols_filename)); + return; + } foreach (CCodeNode node in header_declarations.type_member_declaration.get_children ()) { if (node is CCodeFunction) { diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index f9c5f3ce8..fd90f85ef 100644 --- a/codegen/valagirwriter.vala +++ b/codegen/valagirwriter.vala @@ -1,6 +1,6 @@ /* valagirwriter.vala * - * Copyright (C) 2008-2009 Jürg Billeter + * Copyright (C) 2008-2010 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -87,6 +87,10 @@ public class Vala.GIRWriter : CodeVisitor { string filename = "%s%c%s-%s.gir".printf (directory, Path.DIR_SEPARATOR, gir_namespace, gir_version); stream = FileStream.open (filename, "w"); + if (stream == null) { + Report.error (null, "unable to open `%s' for writing".printf (filename)); + return; + } stream.printf ("\n"); diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index eeb01edd0..ad69e45ca 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -70,6 +70,10 @@ public class Vala.CodeWriter : CodeVisitor { this.context = context; stream = FileStream.open (filename, "w"); + if (stream == null) { + Report.error (null, "unable to open `%s' for writing".printf (filename)); + return; + } write_string ("/* %s generated by %s, do not modify. */".printf (Path.get_basename (filename), Environment.get_prgname ())); write_newline ();