]> 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>
Sun, 7 Mar 2021 12:42:16 +0000 (13:42 +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 a74714d9e2ae56b827df497b735fd6bb8a085628..32bd92fc551a5e37f46ae5ff9dd2865ddfc99e35 100644 (file)
@@ -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 (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 9c5a6846cdc683c5ca3bc25f745ac7cdb4968bb4..cca88d2054d5b33e961df9eb934701f071e46a96 100644 (file)
@@ -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 (')');