From: Juerg Billeter Date: Sun, 11 May 2008 13:57:44 +0000 (+0000) Subject: Fix crash when opening output file fails, fixes bug 466573 X-Git-Tag: VALA_0_3_2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc490edf52f9b3a8dfe14d949d44e1d8fc6b441d;p=thirdparty%2Fvala.git Fix crash when opening output file fails, fixes bug 466573 2008-05-11 Juerg Billeter * ccode/valaccodewriter.vala: * gobject/valaccodegeneratorsourcefile.vala: Fix crash when opening output file fails, fixes bug 466573 svn path=/trunk/; revision=1370 --- diff --git a/ChangeLog b/ChangeLog index 7a0e1e513..9e62bd10f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-05-11 Jürg Billeter + + * ccode/valaccodewriter.vala: + * gobject/valaccodegeneratorsourcefile.vala: + + Fix crash when opening output file fails, fixes bug 466573 + 2008-05-11 Jürg Billeter * gobject/valaccodegenerator.vala: fix freeing nested GLists and diff --git a/ccode/valaccodewriter.vala b/ccode/valaccodewriter.vala index c011c8106..4330e7a48 100644 --- a/ccode/valaccodewriter.vala +++ b/ccode/valaccodewriter.vala @@ -35,13 +35,6 @@ public class Vala.CCodeWriter : Object { } construct { _filename = value; - file_exists = FileUtils.test (_filename, FileTest.EXISTS); - if (file_exists) { - temp_filename = "%s.valatmp".printf (_filename); - stream = FileStream.open (temp_filename, "w"); - } else { - stream = FileStream.open (_filename, "w"); - } } } @@ -71,7 +64,25 @@ public class Vala.CCodeWriter : Object { public CCodeWriter (string _filename) { filename = _filename; } - + + /** + * Opens the file. + * + * @return true if the file has been opened successfully, + * false otherwise + */ + public bool open () { + file_exists = FileUtils.test (_filename, FileTest.EXISTS); + if (file_exists) { + temp_filename = "%s.valatmp".printf (_filename); + stream = FileStream.open (temp_filename, "w"); + } else { + stream = FileStream.open (_filename, "w"); + } + + return (stream != null); + } + /** * Closes the file. */ diff --git a/gobject/valaccodegeneratorsourcefile.vala b/gobject/valaccodegeneratorsourcefile.vala index 3c36ad2ee..c77d49510 100644 --- a/gobject/valaccodegeneratorsourcefile.vala +++ b/gobject/valaccodegeneratorsourcefile.vala @@ -297,6 +297,10 @@ public class Vala.CCodeGenerator { } var writer = new CCodeWriter (source_file.get_cheader_filename ()); + if (!writer.open ()) { + Report.error (null, "unable to open `%s' for writing".printf (writer.filename)); + return; + } if (comment != null) { comment.write (writer); } @@ -323,6 +327,10 @@ public class Vala.CCodeGenerator { writer.close (); writer = new CCodeWriter (source_file.get_csource_filename ()); + if (!writer.open ()) { + Report.error (null, "unable to open `%s' for writing".printf (writer.filename)); + return; + } writer.line_directives = context.debug; if (comment != null) { comment.write (writer);