From b39798267d48fb95b14a7fd634efc0f5ca8807d5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 12 Dec 2011 18:37:10 +0000 Subject: [PATCH] g_strcompress: check that source is non-NULL rather than just crashing Calling this function with a NULL argument is considered to be invalid, but one of the regression tests does it anyway (to watch it crash), which seems a good indication that it's expected to be somewhat common. Let's check it rather than segfaulting. Signed-off-by: Simon McVittie Bug: https://bugzilla.gnome.org/show_bug.cgi?id=666113 Reviewed-by: Emmanuele Bassi Reviewed-by: Matthias Clasen --- glib/gstrfuncs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 04f686b40..04ebd62e1 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -2209,8 +2209,13 @@ gchar* g_strcompress (const gchar *source) { const gchar *p = source, *octal; - gchar *dest = g_malloc (strlen (source) + 1); - gchar *q = dest; + gchar *dest; + gchar *q; + + g_return_val_if_fail (source != NULL, NULL); + + dest = g_malloc (strlen (source) + 1); + q = dest; while (*p) {