summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2021-04-07 18:14:16 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2021-04-07 18:14:16 +0200
commit50cbf91db95864299a069d5dba35d8b7f7199941 (patch)
tree87d4ef717933cf8c3c6b6e1b62d8f65068e28dd7
parent959594d15ac614b2a1d8ac71974ea1d6d4e5702b (diff)
downloadvala-50cbf91db95864299a069d5dba35d8b7f7199941.tar.gz
codegen: Don't call *_instance_init() in compact class chainup
Found by -fsanitize=address
-rw-r--r--codegen/valaccodemethodmodule.vala2
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/chainup/class-compact-this.vala29
3 files changed, 31 insertions, 1 deletions
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 8e1e25db1..944d6a00a 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -641,7 +641,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
ccode.add_assignment (get_this_cexpression (), ccall);
}
- if (cl.base_class == null) {
+ if (cl.base_class == null && !(((CreationMethod) m).chain_up && cl.is_compact)) {
var cinitcall = new CCodeFunctionCall (new CCodeIdentifier ("%s_instance_init".printf (get_ccode_lower_case_name (cl, null))));
cinitcall.add_argument (get_this_cexpression ());
if (!cl.is_compact) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3454623d2..a802bc8fb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -143,6 +143,7 @@ TESTS = \
chainup/class-base.vala \
chainup/class-base-foo.vala \
chainup/class-compact-base.vala \
+ chainup/class-compact-this.vala \
chainup/class-object.vala \
chainup/class-this.vala \
chainup/class-this-foo.vala \
diff --git a/tests/chainup/class-compact-this.vala b/tests/chainup/class-compact-this.vala
new file mode 100644
index 000000000..aed1ab3fe
--- /dev/null
+++ b/tests/chainup/class-compact-this.vala
@@ -0,0 +1,29 @@
+[Compact]
+class Foo {
+ public int i = 42;
+ public int j = 23;
+
+ public Foo () {
+ assert (i == 42);
+ j = 23;
+ }
+
+ public Foo.bar () {
+ this ();
+ assert (i == 42);
+ assert (j == 23);
+ }
+}
+
+void main () {
+ {
+ var foo = new Foo ();
+ assert (foo.i == 42);
+ assert (foo.j == 23);
+ }
+ {
+ var foo = new Foo.bar ();
+ assert (foo.i == 42);
+ assert (foo.j == 23);
+ }
+}