[vala/staging: 1/2] vala: Break possible endless loop in SymbolResolver.get_type_for_struct()



commit 6117d0c431a930dad5da0e6113759b5d6204df4a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Nov 28 17:49:53 2018 +0100

    vala: Break possible endless loop in SymbolResolver.get_type_for_struct()
    
    Required to deal with invalid code containing base struct cycles.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/444

 vala/valasymbolresolver.vala | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala
index 8bbd63323..567712061 100644
--- a/vala/valasymbolresolver.vala
+++ b/vala/valasymbolresolver.vala
@@ -323,8 +323,8 @@ public class Vala.SymbolResolver : CodeVisitor {
                }
        }
 
-       DataType get_type_for_struct (Struct st, Struct base_struct) {
-               if (st.base_type != null) {
+       DataType get_type_for_struct (Struct st, Struct? base_st) {
+               if (st != base_st && st.base_type != null) {
                        // make sure that base type is resolved
 
                        if (current_scope == st.scope) {
@@ -340,6 +340,11 @@ public class Vala.SymbolResolver : CodeVisitor {
                        current_scope = old_scope;
                }
 
+               unowned Struct? base_struct = base_st;
+               if (base_struct == null) {
+                       base_struct = st;
+               }
+
                if (base_struct.base_struct != null) {
                        return get_type_for_struct (st, base_struct.base_struct);
                }
@@ -388,7 +393,7 @@ public class Vala.SymbolResolver : CodeVisitor {
                        } else if (sym is Interface) {
                                type = new ObjectType ((Interface) sym);
                        } else if (sym is Struct) {
-                               type = get_type_for_struct ((Struct) sym, (Struct) sym);
+                               type = get_type_for_struct ((Struct) sym, null);
                        } else if (sym is Enum) {
                                type = new EnumValueType ((Enum) sym);
                        } else if (sym is ErrorDomain) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]