]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Fix criticals in string.joinv() with arrays that start with null
authorNahuel Gomez <contact@nahuelgomez.com.ar>
Tue, 25 Jan 2022 17:23:58 +0000 (14:23 -0300)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 9 Feb 2022 21:23:12 +0000 (22:23 +0100)
tests/basic-types/strings.vala
vapi/glib-2.0.vapi

index 22c96b7f9208e9509c14561a6b5a12bbdc6d5005..31eab55ddc56753d48390a458e58d3829f1ec79f 100644 (file)
@@ -66,6 +66,9 @@ void test_string_joinv () {
        s = string.joinv ("-", null);
        assert (s == "");
 
+       s = string.joinv ("-", { null });
+       assert (s == "");
+
        // LeakSanitizer -fsanitize=address
        sa.length = 3;
 }
index 1f70bfd60c31064a3b09947ec284e4958b39bfe0..5796dc21eb9dd81329ad7c245d5d42a9de0c0fb9 100644 (file)
@@ -1213,7 +1213,7 @@ public class string {
                        len += ((!) separator).length * (i - 1);
 
                        string* res = GLib.malloc (len);
-                       void* ptr = string.copy_to_buffer ((void*) res, (!) str_array[0]);
+                       void* ptr = string.copy_to_buffer ((void*) res, (str_array[0] != null) ? ((!) str_array[0]) : "");
                        for (i = 1 ; i < str_array.length ; i++) {
                                ptr = string.copy_to_buffer (ptr, (!) separator);
                                ptr = string.copy_to_buffer (ptr, (str_array[i] != null) ? ((!) str_array[i]) : "");