[vala/wip/issue/894: 233/235] tests: Don't rely on undefined use-after-free behaviour of glibc




commit b34161f2b8571ecfa40ddbfb84bb6dc1e6245a25
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Aug 11 10:03:14 2020 +0200

    tests: Don't rely on undefined use-after-free behaviour of glibc
    
    Makes this check work with musl >= 1.2.1
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736774

 tests/control-flow/bug736774-1.vala |  6 +++---
 tests/control-flow/bug736774-2.vala | 22 +++++++++++++++++-----
 2 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/tests/control-flow/bug736774-1.vala b/tests/control-flow/bug736774-1.vala
index 1fd70a40e..db6c66fac 100644
--- a/tests/control-flow/bug736774-1.vala
+++ b/tests/control-flow/bug736774-1.vala
@@ -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);
 }
diff --git a/tests/control-flow/bug736774-2.vala b/tests/control-flow/bug736774-2.vala
index f54ce5cbd..a7d983f96 100644
--- a/tests/control-flow/bug736774-2.vala
+++ b/tests/control-flow/bug736774-2.vala
@@ -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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]