[gjs/gnome-3-24] arg: don't crash when asked to convert a null strv to an array



commit cd027725d23d39afdba67a7b64be29e7b5db4171
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Mon Nov 28 14:41:15 2016 +0100

    arg: don't crash when asked to convert a null strv to an array
    
    In that case, return an empty array.
    
    (Different from its counterpart on master: test removed because it would
    require gobject-introspection 1.53)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=775679

 gi/arg.cpp |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 16a265a..3c3af34 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -572,7 +572,13 @@ gjs_array_from_strv(JSContext             *context,
     guint i;
     JS::AutoValueVector elems(context);
 
-    for (i = 0; strv[i] != NULL; i++) {
+    /* We treat a NULL strv as an empty array, since this function should always
+     * set an array value when returning true.
+     * Another alternative would be to set value_p to JS::NullValue, but clients
+     * would need to always check for both an empty array and null if that was
+     * the case.
+     */
+    for (i = 0; strv != NULL && strv[i] != NULL; i++) {
         elems.growBy(1);
         if (!gjs_string_from_utf8(context, strv[i], -1, elems[i]))
             return false;


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