]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Always initialize temp variables to fix fatal warnings of GCC 4.8
authorLuca Bruno <lucabru@src.gnome.org>
Wed, 12 Jun 2013 20:56:36 +0000 (22:56 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Wed, 12 Jun 2013 20:59:51 +0000 (22:59 +0200)
GCC 4.8 is being strict on possible uninitialized variables.
This may or not may be a temporary solution. Always initializing
variables shouldn't be a problem, apart missing possible bugs
in the generated code.

codegen/valaccodebasemodule.vala
vala/valalocalvariable.vala

index d55d3f772e3fcfb5abe9fa1f3f3dbf72704bda9b..ec477ccc35e8a30b6660c5b044ab85bf844b6deb 100644 (file)
@@ -3406,32 +3406,27 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        }
        
        public void emit_temp_var (LocalVariable local) {
-               var init = !(local.name.has_prefix ("*") || local.no_init);
                if (is_in_coroutine ()) {
                        closure_struct.add_field (get_ccode_name (local.variable_type), local.name);
 
                        // even though closure struct is zerod, we need to initialize temporary variables
                        // as they might be used multiple times when declared in a loop
 
-                       if (init) {
-                               var initializer = default_value_for_type (local.variable_type, false);
-                               if (initializer == null) {
-                                       cfile.add_include ("string.h");
-                                       var memset_call = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
-                                       memset_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (local.name)));
-                                       memset_call.add_argument (new CCodeConstant ("0"));
-                                       memset_call.add_argument (new CCodeIdentifier ("sizeof (%s)".printf (get_ccode_name (local.variable_type))));
-                                       ccode.add_expression (memset_call);
-                               } else {
-                                       ccode.add_assignment (get_variable_cexpression (local.name), initializer);
-                               }
+                       var initializer = default_value_for_type (local.variable_type, false);
+                       if (initializer == null) {
+                               cfile.add_include ("string.h");
+                               var memset_call = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
+                               memset_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (local.name)));
+                               memset_call.add_argument (new CCodeConstant ("0"));
+                               memset_call.add_argument (new CCodeIdentifier ("sizeof (%s)".printf (get_ccode_name (local.variable_type))));
+                               ccode.add_expression (memset_call);
+                       } else {
+                               ccode.add_assignment (get_variable_cexpression (local.name), initializer);
                        }
                } else {
                        var cvar = new CCodeVariableDeclarator (local.name, null, get_ccode_declarator_suffix (local.variable_type));
-                       if (init) {
-                               cvar.initializer = default_value_for_type (local.variable_type, true);
-                               cvar.init0 = true;
-                       }
+                       cvar.initializer = default_value_for_type (local.variable_type, true);
+                       cvar.init0 = true;
                        ccode.add_declaration (get_ccode_name (local.variable_type), cvar);
                }
        }
index 4fd8daf9f4a75f75a8f874e0052222b056b8445b..9f4ff592c28015d4b544f6331b29c5af52753f8e 100644 (file)
@@ -35,6 +35,7 @@ public class Vala.LocalVariable : Variable {
 
        public bool captured { get; set; }
 
+       /* Currently ignored due to GCC 4.8 being strict on possibly uninitialized variables */
        public bool no_init { get; set; }
 
        /**