[gtksourceview] snippet: be a bit more defensive with snippets



commit 73b7c99e568487d3b827dd4eed089f89ed7afbc3
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 13 17:43:27 2022 -0700

    snippet: be a bit more defensive with snippets

 gtksourceview/gtksourcesnippet.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/gtksourcesnippet.c b/gtksourceview/gtksourcesnippet.c
index 5a780f3f..3d3b5ffc 100644
--- a/gtksourceview/gtksourcesnippet.c
+++ b/gtksourceview/gtksourcesnippet.c
@@ -211,12 +211,18 @@ GtkSourceSnippetChunk *
 gtk_source_snippet_get_nth_chunk (GtkSourceSnippet *snippet,
                                   guint             nth)
 {
+       GtkSourceSnippetChunk *chunk = NULL;
+
        g_return_val_if_fail (GTK_SOURCE_IS_SNIPPET (snippet), 0);
 
        if (nth < snippet->chunks.length)
-               return g_queue_peek_nth (&snippet->chunks, nth);
+       {
+               chunk = g_queue_peek_nth (&snippet->chunks, nth);
+       }
+
+       g_return_val_if_fail (!chunk || GTK_SOURCE_IS_SNIPPET_CHUNK (chunk), NULL);
 
-       return NULL;
+       return chunk;
 }
 
 /**
@@ -850,11 +856,11 @@ gtk_source_snippet_add_chunk (GtkSourceSnippet      *snippet,
        g_return_if_fail (GTK_SOURCE_IS_SNIPPET (snippet));
        g_return_if_fail (GTK_SOURCE_IS_SNIPPET_CHUNK (chunk));
        g_return_if_fail (!snippet->inserted);
-       g_return_if_fail (chunk->link.data != NULL);
+       g_return_if_fail (chunk->link.data == chunk);
        g_return_if_fail (chunk->link.prev == NULL);
        g_return_if_fail (chunk->link.next == NULL);
 
-       g_object_ref_sink (chunk);
+       g_object_ref (chunk);
 
        g_queue_push_tail_link (&snippet->chunks, &chunk->link);
 


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