]> 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>
Fri, 4 Feb 2022 18:59:14 +0000 (19:59 +0100)
tests/basic-types/strings.c-expected
tests/basic-types/strings.vala
tests/methods/bug723195.c-expected
vapi/glib-2.0.vapi

index 69f4443566108be964dfc284f1f3e4eb05f350f6..06f6e0b67f8827b5c2b16a0aae9608ebd294a240 100644 (file)
@@ -288,11 +288,12 @@ _vala_g_strjoinv (const gchar* separator,
                gint _tmp17_;
                const gchar* res = NULL;
                void* _tmp18_;
-               void* ptr = NULL;
-               const gchar* _tmp19_;
+               const gchar* _tmp19_ = NULL;
                const gchar* _tmp20_;
-               void* _tmp21_;
-               const gchar* _tmp31_;
+               void* ptr = NULL;
+               const gchar* _tmp22_;
+               void* _tmp23_;
+               const gchar* _tmp33_;
                len = (gsize) 1;
                {
                        gboolean _tmp4_ = FALSE;
@@ -357,54 +358,61 @@ _vala_g_strjoinv (const gchar* separator,
                len += (gsize) (_tmp17_ * (i - 1));
                _tmp18_ = g_malloc (len);
                res = _tmp18_;
-               _tmp19_ = res;
                _tmp20_ = str_array[0];
-               _tmp21_ = g_stpcpy ((void*) _tmp19_, (const gchar*) _tmp20_);
-               ptr = _tmp21_;
+               if (_tmp20_ != NULL) {
+                       const gchar* _tmp21_;
+                       _tmp21_ = str_array[0];
+                       _tmp19_ = (const gchar*) _tmp21_;
+               } else {
+                       _tmp19_ = "";
+               }
+               _tmp22_ = res;
+               _tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
+               ptr = _tmp23_;
                {
-                       gboolean _tmp22_ = FALSE;
+                       gboolean _tmp24_ = FALSE;
                        i = 1;
-                       _tmp22_ = TRUE;
+                       _tmp24_ = TRUE;
                        while (TRUE) {
-                               void* _tmp24_;
-                               void* _tmp25_;
-                               const gchar* _tmp26_ = NULL;
-                               const gchar* _tmp27_;
-                               void* _tmp29_;
-                               void* _tmp30_;
-                               if (!_tmp22_) {
-                                       gint _tmp23_;
-                                       _tmp23_ = i;
-                                       i = _tmp23_ + 1;
+                               void* _tmp26_;
+                               void* _tmp27_;
+                               const gchar* _tmp28_ = NULL;
+                               const gchar* _tmp29_;
+                               void* _tmp31_;
+                               void* _tmp32_;
+                               if (!_tmp24_) {
+                                       gint _tmp25_;
+                                       _tmp25_ = i;
+                                       i = _tmp25_ + 1;
                                }
-                               _tmp22_ = FALSE;
+                               _tmp24_ = FALSE;
                                if (!(i < str_array_length1)) {
                                        break;
                                }
-                               _tmp24_ = ptr;
-                               _tmp25_ = g_stpcpy (_tmp24_, (const gchar*) separator);
-                               ptr = _tmp25_;
-                               _tmp27_ = str_array[i];
-                               if (_tmp27_ != NULL) {
-                                       const gchar* _tmp28_;
-                                       _tmp28_ = str_array[i];
-                                       _tmp26_ = (const gchar*) _tmp28_;
+                               _tmp26_ = ptr;
+                               _tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
+                               ptr = _tmp27_;
+                               _tmp29_ = str_array[i];
+                               if (_tmp29_ != NULL) {
+                                       const gchar* _tmp30_;
+                                       _tmp30_ = str_array[i];
+                                       _tmp28_ = (const gchar*) _tmp30_;
                                } else {
-                                       _tmp26_ = "";
+                                       _tmp28_ = "";
                                }
-                               _tmp29_ = ptr;
-                               _tmp30_ = g_stpcpy (_tmp29_, _tmp26_);
-                               ptr = _tmp30_;
+                               _tmp31_ = ptr;
+                               _tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
+                               ptr = _tmp32_;
                        }
                }
-               _tmp31_ = res;
+               _tmp33_ = res;
                res = NULL;
-               result = (gchar*) _tmp31_;
+               result = (gchar*) _tmp33_;
                return result;
        } else {
-               gchar* _tmp32_;
-               _tmp32_ = g_strdup ("");
-               result = _tmp32_;
+               gchar* _tmp34_;
+               _tmp34_ = g_strdup ("");
+               result = _tmp34_;
                return result;
        }
 }
@@ -426,6 +434,11 @@ test_string_joinv (void)
        const gchar* _tmp7_;
        gchar* _tmp8_;
        const gchar* _tmp9_;
+       gchar** _tmp10_;
+       gchar** _tmp11_;
+       gint _tmp11__length1;
+       gchar* _tmp12_;
+       const gchar* _tmp13_;
        _tmp0_ = g_strdup ("hello");
        _tmp1_ = g_strdup ("my");
        _tmp2_ = g_strdup ("world");
@@ -451,6 +464,16 @@ test_string_joinv (void)
        s = _tmp8_;
        _tmp9_ = s;
        _vala_assert (g_strcmp0 (_tmp9_, "") == 0, "s == \"\"");
+       _tmp10_ = g_new0 (gchar*, 1 + 1);
+       _tmp10_[0] = NULL;
+       _tmp11_ = _tmp10_;
+       _tmp11__length1 = 1;
+       _tmp12_ = _vala_g_strjoinv ("-", _tmp11_, (gint) 1);
+       _g_free0 (s);
+       s = _tmp12_;
+       _tmp11_ = (_vala_array_free (_tmp11_, _tmp11__length1, (GDestroyNotify) g_free), NULL);
+       _tmp13_ = s;
+       _vala_assert (g_strcmp0 (_tmp13_, "") == 0, "s == \"\"");
        sa_length1 = 3;
        _g_free0 (s);
        sa = (_vala_array_free (sa, sa_length1, (GDestroyNotify) g_free), NULL);
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 4ba16552b17e9cfd32acda9edbd2a59dd37bb09c..a78ebb0ea2af21028c05a7191f8883a4fe568809 100644 (file)
@@ -55,11 +55,12 @@ _vala_g_strjoinv (const gchar* separator,
                gint _tmp17_;
                const gchar* res = NULL;
                void* _tmp18_;
-               void* ptr = NULL;
-               const gchar* _tmp19_;
+               const gchar* _tmp19_ = NULL;
                const gchar* _tmp20_;
-               void* _tmp21_;
-               const gchar* _tmp31_;
+               void* ptr = NULL;
+               const gchar* _tmp22_;
+               void* _tmp23_;
+               const gchar* _tmp33_;
                len = (gsize) 1;
                {
                        gboolean _tmp4_ = FALSE;
@@ -124,54 +125,61 @@ _vala_g_strjoinv (const gchar* separator,
                len += (gsize) (_tmp17_ * (i - 1));
                _tmp18_ = g_malloc (len);
                res = _tmp18_;
-               _tmp19_ = res;
                _tmp20_ = str_array[0];
-               _tmp21_ = g_stpcpy ((void*) _tmp19_, (const gchar*) _tmp20_);
-               ptr = _tmp21_;
+               if (_tmp20_ != NULL) {
+                       const gchar* _tmp21_;
+                       _tmp21_ = str_array[0];
+                       _tmp19_ = (const gchar*) _tmp21_;
+               } else {
+                       _tmp19_ = "";
+               }
+               _tmp22_ = res;
+               _tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
+               ptr = _tmp23_;
                {
-                       gboolean _tmp22_ = FALSE;
+                       gboolean _tmp24_ = FALSE;
                        i = 1;
-                       _tmp22_ = TRUE;
+                       _tmp24_ = TRUE;
                        while (TRUE) {
-                               void* _tmp24_;
-                               void* _tmp25_;
-                               const gchar* _tmp26_ = NULL;
-                               const gchar* _tmp27_;
-                               void* _tmp29_;
-                               void* _tmp30_;
-                               if (!_tmp22_) {
-                                       gint _tmp23_;
-                                       _tmp23_ = i;
-                                       i = _tmp23_ + 1;
+                               void* _tmp26_;
+                               void* _tmp27_;
+                               const gchar* _tmp28_ = NULL;
+                               const gchar* _tmp29_;
+                               void* _tmp31_;
+                               void* _tmp32_;
+                               if (!_tmp24_) {
+                                       gint _tmp25_;
+                                       _tmp25_ = i;
+                                       i = _tmp25_ + 1;
                                }
-                               _tmp22_ = FALSE;
+                               _tmp24_ = FALSE;
                                if (!(i < str_array_length1)) {
                                        break;
                                }
-                               _tmp24_ = ptr;
-                               _tmp25_ = g_stpcpy (_tmp24_, (const gchar*) separator);
-                               ptr = _tmp25_;
-                               _tmp27_ = str_array[i];
-                               if (_tmp27_ != NULL) {
-                                       const gchar* _tmp28_;
-                                       _tmp28_ = str_array[i];
-                                       _tmp26_ = (const gchar*) _tmp28_;
+                               _tmp26_ = ptr;
+                               _tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
+                               ptr = _tmp27_;
+                               _tmp29_ = str_array[i];
+                               if (_tmp29_ != NULL) {
+                                       const gchar* _tmp30_;
+                                       _tmp30_ = str_array[i];
+                                       _tmp28_ = (const gchar*) _tmp30_;
                                } else {
-                                       _tmp26_ = "";
+                                       _tmp28_ = "";
                                }
-                               _tmp29_ = ptr;
-                               _tmp30_ = g_stpcpy (_tmp29_, _tmp26_);
-                               ptr = _tmp30_;
+                               _tmp31_ = ptr;
+                               _tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
+                               ptr = _tmp32_;
                        }
                }
-               _tmp31_ = res;
+               _tmp33_ = res;
                res = NULL;
-               result = (gchar*) _tmp31_;
+               result = (gchar*) _tmp33_;
                return result;
        } else {
-               gchar* _tmp32_;
-               _tmp32_ = g_strdup ("");
-               result = _tmp32_;
+               gchar* _tmp34_;
+               _tmp34_ = g_strdup ("");
+               result = _tmp34_;
                return result;
        }
 }
index 2caa1b6e8b32e5e6e26c68ab3096e9781141012c..74a683e64376afd176da774831856d045c041590 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]) : "");