changeset 32659:3af16402f176

Add some NULL checks. Now it should not crash even if you don't have the default theme installed (which you won't since it's not even written yet!) You just won't see anything...
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Wed, 21 Sep 2011 07:01:58 +0000
parents 90264301600f
children 68fe7b5211a7
files pidgin/gtkconv-theme.c pidgin/gtkconv.c
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkconv-theme.c	Wed Sep 21 06:45:26 2011 +0000
+++ b/pidgin/gtkconv-theme.c	Wed Sep 21 07:01:58 2011 +0000
@@ -498,6 +498,9 @@
 pidgin_conversation_theme_get_info(const PidginConvTheme *theme)
 {
 	PidginConvThemePrivate *priv;
+
+	g_return_val_if_fail(theme != NULL, NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 	return priv->info;
 }
@@ -506,6 +509,9 @@
 pidgin_conversation_theme_set_info(PidginConvTheme *theme, GHashTable *info)
 {
 	PidginConvThemePrivate *priv;
+
+	g_return_if_fail(theme != NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 
 	if (priv->info)
@@ -518,6 +524,9 @@
 pidgin_conversation_theme_lookup(PidginConvTheme *theme, const char *key, gboolean specific)
 {
 	PidginConvThemePrivate *priv;
+
+	g_return_val_if_fail(theme != NULL, NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 
 	return get_key(priv, key, specific);
@@ -530,6 +539,8 @@
 	const char *dir;
 	const char *html;
 
+	g_return_val_if_fail(theme != NULL, NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 	dir = purple_theme_get_dir(PURPLE_THEME(theme));
 
@@ -593,6 +604,10 @@
 pidgin_conversation_theme_add_variant(PidginConvTheme *theme, char *variant)
 {
 	PidginConvThemePrivate *priv;
+
+	g_return_if_fail(theme != NULL);
+	g_return_if_fail(variant != NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 
 	priv->variants = g_list_prepend(priv->variants, variant);
@@ -602,6 +617,9 @@
 pidgin_conversation_theme_get_variant(PidginConvTheme *theme)
 {
 	PidginConvThemePrivate *priv;
+
+	g_return_val_if_fail(theme != NULL, NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 
 	return g_strdup(priv->variant);
@@ -613,6 +631,10 @@
 	PidginConvThemePrivate *priv;
 	const GValue *val;
 	char *prefname;
+
+	g_return_if_fail(theme != NULL);
+	g_return_if_fail(variant != NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->variant);
@@ -629,6 +651,9 @@
 pidgin_conversation_theme_get_variants(PidginConvTheme *theme)
 {
 	PidginConvThemePrivate *priv;
+
+	g_return_val_if_fail(theme != NULL, NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 
 	return priv->variants;
@@ -640,6 +665,8 @@
 	const char *dir;
 	char *filename;
 
+	g_return_val_if_fail(theme != NULL, NULL);
+
 	dir = purple_theme_get_dir(PURPLE_THEME(theme));
 	filename = g_build_filename(dir, "Contents", "Resources", "Template.html", NULL);
 
@@ -657,6 +684,8 @@
 	PidginConvThemePrivate *priv;
 	const char *dir;
 
+	g_return_val_if_fail(theme != NULL, NULL);
+
 	priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
 
 	dir = purple_theme_get_dir(PURPLE_THEME(theme));
--- a/pidgin/gtkconv.c	Wed Sep 21 06:45:26 2011 +0000
+++ b/pidgin/gtkconv.c	Wed Sep 21 07:01:58 2011 +0000
@@ -5031,6 +5031,9 @@
 	char *path;
 
 	text = pidgin_conversation_theme_get_template(theme, PIDGIN_CONVERSATION_THEME_TEMPLATE_MAIN);
+	if (text == NULL)
+		return NULL;
+
 	ms = g_strsplit(text, "%@", 6);
 	if (ms[0] == NULL || ms[1] == NULL || ms[2] == NULL || ms[3] == NULL || ms[4] == NULL || ms[5] == NULL) {
 		g_strfreev(ms);
@@ -5977,10 +5980,14 @@
 	PurpleMessageFlags flags,
 	time_t mtime)
 {
-	GString *str = g_string_new(NULL);
+	GString *str;
 	const char *cur = text;
 	const char *prev = cur;
 
+	if (text == NULL)
+		return g_strdup("");
+
+	str = g_string_new(NULL);
 	while ((cur = strchr(cur, '%'))) {
 		const char *replace = NULL;
 		const char *fin = NULL;