[evolution-data-server/gnome-3-8] Switch NULL to empty string in e_util_utf8_{data_}make_valid()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/gnome-3-8] Switch NULL to empty string in e_util_utf8_{data_}make_valid()
- Date: Tue, 16 Apr 2013 14:59:52 +0000 (UTC)
commit c57c399e0b7f102f5239c95b97c785cf831a8ec8
Author: Milan Crha <mcrha redhat com>
Date: Tue Apr 16 16:51:50 2013 +0200
Switch NULL to empty string in e_util_utf8_{data_}make_valid()
It's used on various places which expect a valid string, but which
doesn't check for NULL values of the string, which can cause a crash,
like xtian found with e_data_cal_respond_get_object(), which can have
passed in a NULL object. This change is also to avoid NULL-checking
on too many places.
libedataserver/e-data-server-util.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index 03f07d9..864da07 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -461,6 +461,7 @@ e_util_utf8_remove_accents (const gchar *str)
*
* Returns a newly-allocated copy of @str, with invalid characters
* replaced by Unicode replacement characters (U+FFFD).
+ * For %NULL @str returns newly allocated empty string ("").
*
* Returns: a newly-allocated string
*
@@ -469,6 +470,9 @@ e_util_utf8_remove_accents (const gchar *str)
gchar *
e_util_utf8_make_valid (const gchar *str)
{
+ if (!str)
+ return g_strdup ("");
+
return e_util_utf8_data_make_valid (str, strlen (str));
}
@@ -479,6 +483,7 @@ e_util_utf8_make_valid (const gchar *str)
*
* Returns a newly-allocated NULL-terminated string with invalid characters
* replaced by Unicode replacement characters (U+FFFD).
+ * For %NULL @data returns newly allocated empty string ("").
*
* Returns: a newly-allocated string
*
@@ -493,7 +498,8 @@ e_util_utf8_data_make_valid (const gchar *data,
const gchar *remainder, *invalid;
gint remaining_bytes, valid_bytes;
- g_return_val_if_fail (data != NULL, NULL);
+ if (!data)
+ return g_strdup ("");
string = NULL;
remainder = (gchar *) data,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]