]> 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, 16 Feb 2022 17:32:51 +0000 (18:32 +0100)
tests/basic-types/strings.vala
vapi/glib-2.0.vapi

index 99136bee1f81205262d64e247d9cbe0950e7d320..c11342f11ee0ec5710304c9de559a41a35d2fa51 100644 (file)
@@ -53,6 +53,9 @@ void test_string_joinv () {
        s = string.joinv ("-", null);
        assert (s == "");
 
+       s = string.joinv ("-", { null });
+       assert (s == "");
+
        // LeakSanitizer -fsanitize=address
        sa.length = 3;
 }
index 6b31dca9c4f3217176e34315f149b203d3da21f3..7d9b3c8695c000efebd7ee6ab26721918352a29a 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]) : "");