]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Don't leak array if length is -1
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 4 Feb 2021 09:55:31 +0000 (10:55 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 27 Feb 2021 19:08:22 +0000 (20:08 +0100)
Found by -fsanitize=address

tests/basic-types/strings.vala
tests/methods/bug723195.vala
tests/objects/bug751338.vala
tests/objects/methods.vala

index 219dde7c848c0a5769b242207a08541dd918030f..5185a9ec32197e353d7e2d0688f4e76e93e52ea7 100644 (file)
@@ -60,6 +60,9 @@ void test_string_joinv () {
 
        s = string.joinv ("-", null);
        assert (s == "");
+
+       // LeakSanitizer -fsanitize=address
+       sa.length = 3;
 }
 
 void test_string_replace () {
index e0676cb2962dba0ae5153324e001911d9b6d4a20..c7dcf13accbe072bddb605918bdbe0d628e052b1 100644 (file)
@@ -20,4 +20,7 @@ void main () {
        assert (string.joinv (":", a) == "foo:bar");
 
        assert (string.joinv (":", null) == "");
+
+       // LeakSanitizer -fsanitize=address
+       a.length = 4;
 }
index 353071e9dbb55f2f4f1bade2ee94b5d81a1d6c07..a766cca957f3a26ac637dfa2f0f61f34112b3434 100644 (file)
@@ -16,6 +16,11 @@ void main() {
        assert (strings[0] == "foo");
        assert (strings[1] == "bar");
 
+       // LeakSanitizer -fsanitize=address
+       if (strings.length == -1) {
+               strings.length = (int) strv_length (strings);
+       }
+
        f.set("strings", null);
        f.get("strings", out strings);
        assert(strings == null);
@@ -24,4 +29,9 @@ void main() {
        f.get("strings", out strings);
        assert (strings[0] == "foo");
        assert (strings[1] == "bar");
+
+       // LeakSanitizer -fsanitize=address
+       if (strings.length == -1) {
+               strings.length = (int) strv_length (strings);
+       }
 }
index cfacc9c735783258870e0be9fcde5d373df7fc12..30043e26aa2882c28c595c3df786ec7d63bcede4 100644 (file)
@@ -84,6 +84,11 @@ class Maman.SubBar : Bar {
                assert (array[1] == "world");
                assert (array.length < 0);
 
+               // LeakSanitizer -fsanitize=address
+               if (array.length == -1) {
+                       array.length = (int) strv_length (array);
+               }
+
                ClassTest.run_test ();
 
                return 0;