[vala/staging: 1/4] vala: Add missing null-check in DataType.get_type_signature()




commit e4991e34c6f8075d6e3b53eb97a32340687f3072
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Mar 7 13:42:16 2021 +0100

    vala: Add missing null-check in DataType.get_type_signature()
    
    If an instance struct field can not be resolved to a valid
    type-signature then bail.
    
    This fixes criticals like:
    
        g_string_insert_len: assertion 'len == 0 || val != NULL' failed

 tests/Makefile.am                          |  1 +
 tests/generics/gvariant-serialization.test | 10 ++++++++++
 vala/valadatatype.vala                     |  7 ++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a74714d9e..32bd92fc5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -668,6 +668,7 @@ TESTS = \
        generics/arrays-not-supported-3.test \
        generics/constructor-chain-up.vala \
        generics/floating-type-cast.vala \
+       generics/gvariant-serialization.test \
        generics/inference-argument-may-fail.vala \
        generics/inference-static-function.vala \
        generics/integer-type-cast.vala \
diff --git a/tests/generics/gvariant-serialization.test b/tests/generics/gvariant-serialization.test
new file mode 100644
index 000000000..e9f9ad593
--- /dev/null
+++ b/tests/generics/gvariant-serialization.test
@@ -0,0 +1,10 @@
+Invalid Code
+
+struct Foo<G> {
+       public G g;
+}
+
+void main () {
+       var foo = new Foo<string>[] {};
+       Variant v = foo;
+}
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 9c5a6846c..cca88d205 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -583,7 +583,12 @@ public abstract class Vala.DataType : CodeNode {
                                str.append_c ('(');
                                foreach (Field f in st.get_fields ()) {
                                        if (f.binding == MemberBinding.INSTANCE) {
-                                               str.append (f.variable_type.get_type_signature (f));
+                                               var s = f.variable_type.get_type_signature (f);
+                                               if (s != null) {
+                                                       str.append (s);
+                                               } else {
+                                                       return null;
+                                               }
                                        }
                                }
                                str.append_c (')');


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