/pidgin/main: 2d7d55acd82c: Coverity: fix null pointer dereferences

Tomasz Wasilczyk <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 2d7d55acd82c0de210064ca5b2c10b1150a9b7fa
Author:	 Tomasz Wasilczyk <[email protected]>
Date:	 2014-05-15 23:02 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/2d7d55acd82c

Description:

Coverity: fix null pointer dereferences

diffstat:

 libpurple/http.c                          |  7 ++++---
 libpurple/protocols/gg/utils.c            |  3 ++-
 libpurple/protocols/yahoo/yahoo_profile.c |  2 +-
 libpurple/request.c                       |  6 ++++--
 4 files changed, 11 insertions(+), 7 deletions(-)

diffs (84 lines):

diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -1944,6 +1944,7 @@ static void purple_http_cookie_jar_parse
 					"Invalid cookie: [%s]\n", cookie);
 			else
 				purple_debug_warning("http", "Invalid cookie.");
+			continue;
 		}
 
 		name = g_strndup(cookie, eqsign - cookie);
@@ -1955,7 +1956,7 @@ static void purple_http_cookie_jar_parse
 
 		if (semicolon != NULL) {
 			GMatchInfo *match_info;
-			GRegex *re_expires = g_regex_new(
+			GRegex *re_expires = g_regex_new( /* XXX: make it static */
 				"expires=([a-z0-9, :]+)",
 				G_REGEX_OPTIMIZE | G_REGEX_CASELESS,
 				G_REGEX_MATCH_NOTEMPTY, NULL);
@@ -2884,7 +2885,7 @@ purple_http_url_parse(const char *raw_ur
 	url->fragment = g_match_info_fetch(match_info, 4);
 	g_match_info_free(match_info);
 
-	if (url->protocol[0] == '\0') {
+	if (g_strcmp0(url->protocol, "") == 0) {
 		g_free(url->protocol);
 		url->protocol = NULL;
 	} else if (url->protocol != NULL) {
@@ -2939,7 +2940,7 @@ purple_http_url_parse(const char *raw_ur
 			g_free(url->password);
 			url->password = NULL;
 		}
-		if (url->host[0] == '\0') {
+		if (g_strcmp0(url->host, "") == 0) {
 			g_free(url->host);
 			url->host = NULL;
 		} else if (url->host != NULL) {
diff --git a/libpurple/protocols/gg/utils.c b/libpurple/protocols/gg/utils.c
--- a/libpurple/protocols/gg/utils.c
+++ b/libpurple/protocols/gg/utils.c
@@ -111,10 +111,11 @@ gboolean ggp_password_validate(const gch
 
 gchar * ggp_utf8_strndup(const gchar *str, gsize n)
 {
-	size_t raw_len = strlen(str);
+	size_t raw_len;
 	gchar *end_ptr;
 	if (str == NULL)
 		return NULL;
+	raw_len = strlen(str);
 	if (raw_len <= n)
 		return g_strdup(str);
 
diff --git a/libpurple/protocols/yahoo/yahoo_profile.c b/libpurple/protocols/yahoo/yahoo_profile.c
--- a/libpurple/protocols/yahoo/yahoo_profile.c
+++ b/libpurple/protocols/yahoo/yahoo_profile.c
@@ -1018,7 +1018,7 @@ yahoo_got_photo(PurpleHttpConnection *ht
 		purple_debug_misc("yahoo", "after utf8 conversion: stripped = (%s)\n", stripped);
 	}
 
-	if (strings && profile_state == PROFILE_STATE_DEFAULT) {
+	if (profile_state == PROFILE_STATE_DEFAULT) {
 #if 0
 	/* extract their Yahoo! ID and put it in. Don't bother marking has_info as
 	 * true, since the Yahoo! ID will always be there */
diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -959,10 +959,12 @@ purple_request_field_destroy(PurpleReque
 			while (it != NULL) {
 				g_free(it->data);
 				it = g_list_next(it); /* value */
+				if (it == NULL) {
+					g_warn_if_reached();
+					break;
+				}
 				if (it->data && field->u.choice.data_destroy)
 					field->u.choice.data_destroy(it->data);
-				if (it == NULL)
-					break;
 				it = g_list_next(it); /* next label */
 			}
 			g_list_free(field->u.choice.elements);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.