[gtk/wip/otte/inspector: 2/2] contentformats: Make sure 0 elements means the array is NULL
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/inspector: 2/2] contentformats: Make sure 0 elements means the array is NULL
- Date: Sat, 11 Dec 2021 22:31:33 +0000 (UTC)
commit 5fbc510f94e5e1c946131c02158c76dea0f5d715
Author: Benjamin Otte <otte redhat com>
Date: Sat Dec 11 23:21:53 2021 +0100
contentformats: Make sure 0 elements means the array is NULL
Don't return arrays with 0 elements, return NULL.
gdk/gdkcontentformats.c | 40 +++++++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/gdk/gdkcontentformats.c b/gdk/gdkcontentformats.c
index 0cdc51fa52..6caaa2ca82 100644
--- a/gdk/gdkcontentformats.c
+++ b/gdk/gdkcontentformats.c
@@ -718,19 +718,33 @@ gdk_content_formats_builder_to_formats (GdkContentFormatsBuilder *builder)
g_return_val_if_fail (builder != NULL, NULL);
- gtypes = g_new (GType, builder->n_gtypes + 1);
- i = builder->n_gtypes;
- gtypes[i--] = G_TYPE_INVALID;
- /* add backwards because most important type is last in the list */
- for (l = builder->gtypes; l; l = l->next)
- gtypes[i--] = GPOINTER_TO_SIZE (l->data);
-
- mime_types = g_new (const char *, builder->n_mime_types + 1);
- i = builder->n_mime_types;
- mime_types[i--] = NULL;
- /* add backwards because most important type is last in the list */
- for (l = builder->mime_types; l; l = l->next)
- mime_types[i--] = l->data;
+ if (builder->n_gtypes > 0)
+ {
+ gtypes = g_new (GType, builder->n_gtypes + 1);
+ i = builder->n_gtypes;
+ gtypes[i--] = G_TYPE_INVALID;
+ /* add backwards because most important type is last in the list */
+ for (l = builder->gtypes; l; l = l->next)
+ gtypes[i--] = GPOINTER_TO_SIZE (l->data);
+ }
+ else
+ {
+ gtypes = NULL;
+ }
+
+ if (builder->n_mime_types > 0)
+ {
+ mime_types = g_new (const char *, builder->n_mime_types + 1);
+ i = builder->n_mime_types;
+ mime_types[i--] = NULL;
+ /* add backwards because most important type is last in the list */
+ for (l = builder->mime_types; l; l = l->next)
+ mime_types[i--] = l->data;
+ }
+ else
+ {
+ mime_types = NULL;
+ }
result = gdk_content_formats_new_take (gtypes, builder->n_gtypes,
mime_types, builder->n_mime_types);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]