summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hergert <chergert@redhat.com>2022-05-13 17:43:27 -0700
committerChristian Hergert <chergert@redhat.com>2022-06-12 10:18:54 -0700
commit256e6cc53c34b586213b07a5a86d8f70021794ff (patch)
treef8d2e8b9c23edf6a496a9a7c51feab81768d280e
parent34f5b43badca2362f80c81f6d23db154a9991ff0 (diff)
downloadgtksourceview-256e6cc53c34b586213b07a5a86d8f70021794ff.tar.gz
snippet: be a bit more defensive with snippets
-rw-r--r--gtksourceview/gtksourcesnippet.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/gtksourceview/gtksourcesnippet.c b/gtksourceview/gtksourcesnippet.c
index 73ab98c6..503d2ba5 100644
--- a/gtksourceview/gtksourcesnippet.c
+++ b/gtksourceview/gtksourcesnippet.c
@@ -210,12 +210,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;
}
/**
@@ -849,11 +855,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);