]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Don't rely on undefined use-after-free behaviour of glibc
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 11 Aug 2020 08:03:14 +0000 (10:03 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 5 Sep 2020 14:05:11 +0000 (16:05 +0200)
Makes this check work with musl >= 1.2.1

https://bugzilla.gnome.org/show_bug.cgi?id=736774

tests/control-flow/bug736774-1.vala
tests/control-flow/bug736774-2.vala

index 1fd70a40e8d2ed16617c0cf2f53dadad86fc8678..db6c66facffe72c7d656a01dedd0b695b052d4e2 100644 (file)
@@ -1,8 +1,8 @@
-bool success = false;
+int success = 0;
 
 class Foo : Object {
        ~Foo() {
-               success = true;
+               success++;
        }
 }
 
@@ -19,5 +19,5 @@ void main() {
        } catch {
        }
 
-       assert (success);
+       assert (success == 1);
 }
index f54ce5cbdc9e49dae0343ae78722d7e602bbe701..a7d983f96100474a3ec1ccf3c906888987291cbf 100644 (file)
@@ -1,8 +1,20 @@
-string* keep;
+int success = 0;
 
-string may_fail () throws GLib.Error {
-       string result = "test";
-       keep = result;
+[Compact]
+[Immutable]
+[CCode (free_function = "vstring_destroy")]
+public class vstring : string {
+       public vstring (string s);
+
+       [DestroysInstance]
+       public void destroy () {
+               free (this);
+               success++;
+       }
+}
+
+vstring may_fail () throws GLib.Error {
+       vstring result = (vstring) "test".dup ();
        return (owned) result;
 }
 
@@ -12,5 +24,5 @@ void main () {
        } catch {
        }
 
-       assert (keep != "test");
+       assert (success == 1);
 }