diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-12-12 18:37:10 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-01-16 17:48:21 +0000 |
commit | 7ddaec08f48296b451f12d47d9275f38eb46c7f3 (patch) | |
tree | db2ce19f97fa565cf3fff30f6bdda1c078a93ba9 | |
parent | 43c18ec7392b3dbdbae7a8056d665e36e44e86a7 (diff) | |
download | glib-7ddaec08f48296b451f12d47d9275f38eb46c7f3.tar.gz |
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 <simon.mcvittie@collabora.co.uk>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=666113
Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
Reviewed-by: Matthias Clasen <mclasen@redhat.com>
-rw-r--r-- | glib/gstrfuncs.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index aecde5b87..aa9decd12 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -2207,8 +2207,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) { |