diff --git a/steam-runtime-tools/json-utils-internal.h b/steam-runtime-tools/json-utils-internal.h index b3e1d208d5b25bc120c7c2002c5b3843a2b7f9d3..c7e0a6793cb799ba9460178d0a61fe53635a2998 100644 --- a/steam-runtime-tools/json-utils-internal.h +++ b/steam-runtime-tools/json-utils-internal.h @@ -41,4 +41,5 @@ guint srt_get_flags_from_json_array (GType flags_type, guint flag_if_unknown); gchar ** _srt_json_object_dup_strv_member (JsonObject *json_obj, - const gchar *array_member); + const gchar *array_member, + const gchar *placeholder); diff --git a/steam-runtime-tools/json-utils.c b/steam-runtime-tools/json-utils.c index 422d2456ec9b4ba1eb6d9b070f327d3fd423e282..160d4458229f3786e59ce34e77ae288d2512c843 100644 --- a/steam-runtime-tools/json-utils.c +++ b/steam-runtime-tools/json-utils.c @@ -84,9 +84,9 @@ out: * @json_obj: (not nullable): A JSON Object used to search for * @array_member property * @array_member: (not nullable): The JSON member to look up - * - * Every %NULL or non string members of the array are replaced with the value - * "<invalid>". + * @placeholder: (nullable): If an item in the array is not a string, + * substitute this non-%NULL value; or if %NULL, behave as though it + * was not present * * Returns: (transfer full) (array zero-terminated=1) (element-type utf8) (nullable): * A string array from the given @json_obj, or %NULL if it doesn't have a @@ -94,7 +94,8 @@ out: */ gchar ** _srt_json_object_dup_strv_member (JsonObject *json_obj, - const gchar *array_member) + const gchar *array_member, + const gchar *placeholder) { JsonArray *array; guint length; @@ -106,20 +107,30 @@ _srt_json_object_dup_strv_member (JsonObject *json_obj, if (json_object_has_member (json_obj, array_member)) { + guint j = 0; + array = json_object_get_array_member (json_obj, array_member); if (array == NULL) return ret; length = json_array_get_length (array); ret = g_new0 (gchar *, length + 1); + for (guint i = 0; i < length; i++) { element = json_array_get_string_element (array, i); + if (element == NULL) - element = "<invalid>"; - ret[i] = g_strdup (element); + element = placeholder; + + if (element == NULL) + continue; + + ret[j++] = g_strdup (element); } - ret[length] = NULL; + + g_assert (j <= length); + ret[j] = NULL; } return ret; diff --git a/steam-runtime-tools/system-info.c b/steam-runtime-tools/system-info.c index 83121dfd35df637436274e6c4ec96b021a0d1efb..2928a68e0b7b264bd7a5578218fb7b6b99715d3b 100644 --- a/steam-runtime-tools/system-info.c +++ b/steam-runtime-tools/system-info.c @@ -1349,9 +1349,13 @@ _srt_system_info_get_pinned_libs_from_report (JsonObject *json_obj, { json_pinned_obj = json_object_get_object_member (json_obj, which); - pinned_list = _srt_json_object_dup_strv_member (json_pinned_obj, "list"); + pinned_list = _srt_json_object_dup_strv_member (json_pinned_obj, + "list", + "<invalid>"); - *messages = _srt_json_object_dup_strv_member (json_pinned_obj, "messages"); + *messages = _srt_json_object_dup_strv_member (json_pinned_obj, + "messages", + "<invalid>"); } return pinned_list; @@ -3232,7 +3236,9 @@ srt_system_info_list_driver_environment (SrtSystemInfo *self) static gchar ** _srt_system_info_driver_environment_from_report (JsonObject *json_obj) { - return _srt_json_object_dup_strv_member (json_obj, "driver_environment"); + return _srt_json_object_dup_strv_member (json_obj, + "driver_environment", + "<invalid>"); } typedef struct