[vala/0.54] glib-2.0: Fix criticals in string.joinv() with arrays that start with null



commit 30f2c3c4daa80554f5af4aa4f900d2bba8217257
Author: Nahuel Gomez <contact nahuelgomez com ar>
Date:   Tue Jan 25 14:23:58 2022 -0300

    glib-2.0: Fix criticals in string.joinv() with arrays that start with null

 tests/basic-types/strings.c-expected | 97 ++++++++++++++++++++++--------------
 tests/basic-types/strings.vala       |  3 ++
 tests/methods/bug723195.c-expected   | 82 ++++++++++++++++--------------
 vapi/glib-2.0.vapi                   |  2 +-
 4 files changed, 109 insertions(+), 75 deletions(-)
---
diff --git a/tests/basic-types/strings.c-expected b/tests/basic-types/strings.c-expected
index 69f444356..06f6e0b67 100644
--- a/tests/basic-types/strings.c-expected
+++ b/tests/basic-types/strings.c-expected
@@ -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);
diff --git a/tests/basic-types/strings.vala b/tests/basic-types/strings.vala
index 22c96b7f9..31eab55dd 100644
--- a/tests/basic-types/strings.vala
+++ b/tests/basic-types/strings.vala
@@ -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;
 }
diff --git a/tests/methods/bug723195.c-expected b/tests/methods/bug723195.c-expected
index 4ba16552b..a78ebb0ea 100644
--- a/tests/methods/bug723195.c-expected
+++ b/tests/methods/bug723195.c-expected
@@ -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;
        }
 }
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 2caa1b6e8..74a683e64 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -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]) 
: "");


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