[vala/0.50] vala: Add missing null-check in DataType.get_type_signature()
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.50] vala: Add missing null-check in DataType.get_type_signature()
- Date: Sun, 14 Mar 2021 15:47:53 +0000 (UTC)
commit e5ff19b1afefa0c1b9e0a8ef25801b6e482f8681
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 7fae2f152..4fc8abce0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
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 bb00ff8cf..2980877cc 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -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 (')');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]