]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix crash when opening file fails
authorJürg Billeter <j@bitron.ch>
Sun, 7 Feb 2010 10:23:48 +0000 (11:23 +0100)
committerJürg Billeter <j@bitron.ch>
Sun, 7 Feb 2010 10:23:48 +0000 (11:23 +0100)
Based on patch by pancake, fixes bug 606837.

ccode/valaccodewriter.vala
codegen/valaccodebasemodule.vala
codegen/valagirwriter.vala
vala/valacodewriter.vala

index ff0677bceba4239b83d63c79ccfca05a32aaba78..f2ddb7e388ea70563b22cbec5184d7680ec8fb01 100644 (file)
@@ -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;
        }
 
        /**
index ae358fc9f6a3116748ab09181687fd9027352543..837481250cd97d712e2f0534bc4a0b7c5eced2e3 100644 (file)
@@ -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) {
index f9c5f3ce8b890a6778a54c80cf2fdeb77756d6ee..fd90f85ef64708ee8fce7079e1ab1905f4efc4ac 100644 (file)
@@ -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 ("<?xml version=\"1.0\"?>\n");
 
index eeb01edd086355f5bf964325a332a9f286d7d6ee..ad69e45cab032ddc26df23789fbe04503f33e4b7 100644 (file)
@@ -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 ();