]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Add missing null-check in DataType.get_type_signature()
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 7 Mar 2021 12:42:16 +0000 (13:42 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 13 Mar 2021 20:29:03 +0000 (21:29 +0100)
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
tests/generics/gvariant-serialization.test [new file with mode: 0644]
vala/valadatatype.vala

index 7fae2f1529a9be344d0bced506b31c523a18abe8..4fc8abce089143e1b75bb8ece79d95d6b37bfd08 100644 (file)
@@ -660,6 +660,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 (file)
index 0000000..e9f9ad5
--- /dev/null
@@ -0,0 +1,10 @@
+Invalid Code
+
+struct Foo<G> {
+       public G g;
+}
+
+void main () {
+       var foo = new Foo<string>[] {};
+       Variant v = foo;
+}
index bb00ff8cf914f59ec05f3e8180603cb0ade1f55b..2980877cce80d79bd71eb798ca7f74e8ca5fe376 100644 (file)
@@ -574,7 +574,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 (')');