summaryrefslogtreecommitdiff
path: root/tests/methods
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2020-03-13 00:01:09 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2020-03-13 13:14:36 +0100
commit4555ed66dcf5839e79e3b9a62ef5cf83bde35d4e (patch)
treef7e5bd3314701b23710c56cb621fdfe5103c880a /tests/methods
parent5490b0b21a4089d803d51c91311430d60d266f7b (diff)
downloadvala-4555ed66dcf5839e79e3b9a62ef5cf83bde35d4e.tar.gz
codegen: Emit postconditions before free'ing local variables
It was possible to cause segmentation-faults or use-after-free errors.
Diffstat (limited to 'tests/methods')
-rw-r--r--tests/methods/postconditions.vala51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/methods/postconditions.vala b/tests/methods/postconditions.vala
new file mode 100644
index 000000000..5cd9c5929
--- /dev/null
+++ b/tests/methods/postconditions.vala
@@ -0,0 +1,51 @@
+void foo (owned string[] a) ensures (a[1] == "bar") {
+}
+
+void foz (ref string[] a) ensures (a[1] == "bar") {
+ a = { "foo", "bar" };
+}
+
+void fom (out string[] a) ensures (a[1] == "bar") {
+ a = { "foo", "bar" };
+}
+
+string[] bar (owned string[] a) ensures (result[0] == "manam" && a[1] == "foo") {
+ return { "manam" };
+}
+
+string[] baz (ref string[] a) ensures (result[0] == "manam" && a[1] == "foo") {
+ a = { "bar", "foo" };
+ return { "manam" };
+}
+
+string[] bam (out string[] a) ensures (result[0] == "manam" && a[1] == "foo") {
+ a = { "bar", "foo" };
+ return { "manam" };
+}
+
+void main () {
+ {
+ foo ({ "foo", "bar" });
+ }
+ {
+ string[] a = {};
+ foz (ref a);
+ assert (a[0] == "foo");
+ }
+ {
+ string[] a;
+ fom (out a);
+ assert (a[0] == "foo");
+ }
+ {
+ assert (bar ({ "bar", "foo" })[0] == "manam");
+ }
+ {
+ string[] a = {};
+ assert (baz (ref a)[0] == "manam");
+ }
+ {
+ string[] a;
+ assert (bam (out a)[0] == "manam");
+ }
+}