[gtksourceview/gtksourceview-5-4] snippet: be a bit more defensive with snippets
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gtksourceview-5-4] snippet: be a bit more defensive with snippets
- Date: Sun, 12 Jun 2022 17:42:46 +0000 (UTC)
commit 256e6cc53c34b586213b07a5a86d8f70021794ff
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 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]