summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--gtk/gtkselection.c38
2 files changed, 41 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b9b585321e..fd76151f3b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-21 Michael Natterer <mitch@imendio.com>
+
+ * gtk/gtkselection.c: add tons of g_return_if_fail() instead of
+ crashing when NULL pointers get passed.
+
2008-04-18 Michael Natterer <mitch@imendio.com>
* gtk/gtkenums.h: move a few '{' to their own lines so all enums
diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c
index bc9c41e42f..0cbd282aee 100644
--- a/gtk/gtkselection.c
+++ b/gtk/gtkselection.c
@@ -952,7 +952,9 @@ gtk_selection_remove_all (GtkWidget *widget)
GList *tmp_list;
GList *next;
GtkSelectionInfo *selection_info;
-
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
/* Remove pending requests/incrs for this widget */
tmp_list = current_retrievals;
@@ -1127,6 +1129,8 @@ gtk_selection_data_set (GtkSelectionData *selection_data,
const guchar *data,
gint length)
{
+ g_return_if_fail (selection_data != NULL);
+
g_free (selection_data->data);
selection_data->type = type;
@@ -1367,6 +1371,8 @@ gtk_selection_data_set_text (GtkSelectionData *selection_data,
const gchar *str,
gint len)
{
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+
if (len < 0)
len = strlen (str);
@@ -1417,6 +1423,8 @@ gtk_selection_data_get_text (GtkSelectionData *selection_data)
{
guchar *result = NULL;
+ g_return_val_if_fail (selection_data != NULL, NULL);
+
init_atoms ();
if (selection_data->length >= 0 &&
@@ -1475,6 +1483,9 @@ gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data,
gchar *str, *type;
gsize len;
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+ g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
+
formats = gdk_pixbuf_get_formats ();
for (f = formats; f; f = f->next)
@@ -1533,6 +1544,8 @@ gtk_selection_data_get_pixbuf (GtkSelectionData *selection_data)
GdkPixbufLoader *loader;
GdkPixbuf *result = NULL;
+ g_return_val_if_fail (selection_data != NULL, NULL);
+
if (selection_data->length > 0)
{
loader = gdk_pixbuf_loader_new ();
@@ -1571,6 +1584,9 @@ gboolean
gtk_selection_data_set_uris (GtkSelectionData *selection_data,
gchar **uris)
{
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+ g_return_val_if_fail (uris != NULL, FALSE);
+
init_atoms ();
if (selection_data->target == text_uri_list_atom)
@@ -1625,6 +1641,8 @@ gtk_selection_data_get_uris (GtkSelectionData *selection_data)
{
gchar **result = NULL;
+ g_return_val_if_fail (selection_data != NULL, NULL);
+
init_atoms ();
if (selection_data->length >= 0 &&
@@ -1667,6 +1685,8 @@ gtk_selection_data_get_targets (GtkSelectionData *selection_data,
GdkAtom **targets,
gint *n_atoms)
{
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+
if (selection_data->length >= 0 &&
selection_data->format == 32 &&
selection_data->type == GDK_SELECTION_TYPE_ATOM)
@@ -1704,11 +1724,13 @@ gtk_selection_data_get_targets (GtkSelectionData *selection_data,
**/
gboolean
gtk_targets_include_text (GdkAtom *targets,
- gint n_targets)
+ gint n_targets)
{
gint i;
gboolean result = FALSE;
+ g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
+
/* Keep in sync with gtk_target_list_add_text_targets()
*/
@@ -1756,6 +1778,7 @@ gtk_targets_include_rich_text (GdkAtom *targets,
gint i, j;
gboolean result = FALSE;
+ g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
init_atoms ();
@@ -1799,6 +1822,8 @@ gtk_selection_data_targets_include_text (GtkSelectionData *selection_data)
gint n_targets;
gboolean result = FALSE;
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+
init_atoms ();
if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets))
@@ -1833,6 +1858,7 @@ gtk_selection_data_targets_include_rich_text (GtkSelectionData *selection_data,
gint n_targets;
gboolean result = FALSE;
+ g_return_val_if_fail (selection_data != NULL, FALSE);
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
init_atoms ();
@@ -1871,6 +1897,8 @@ gtk_targets_include_image (GdkAtom *targets,
gint i;
gboolean result = FALSE;
+ g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
+
list = gtk_target_list_new (NULL, 0);
gtk_target_list_add_image_targets (list, 0, writable);
for (i = 0; i < n_targets && !result; i++)
@@ -1913,6 +1941,8 @@ gtk_selection_data_targets_include_image (GtkSelectionData *selection_data,
gint n_targets;
gboolean result = FALSE;
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+
init_atoms ();
if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets))
@@ -1944,6 +1974,8 @@ gtk_targets_include_uri (GdkAtom *targets,
gint i;
gboolean result = FALSE;
+ g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
+
/* Keep in sync with gtk_target_list_add_uri_targets()
*/
@@ -1981,6 +2013,8 @@ gtk_selection_data_targets_include_uri (GtkSelectionData *selection_data)
gint n_targets;
gboolean result = FALSE;
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+
init_atoms ();
if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets))