pidgin: 60a632cb: log_reader: strchr(), and some simplifyi...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Thu Jul 21 01:45:49 EDT 2011


----------------------------------------------------------------------
Revision: 60a632cb295df557713697e92727d551d7345451
Parent:   abf0c7744ea5b27942257ab98f6c0dba7480778a
Author:   darkrain42 at pidgin.im
Date:     07/21/11 01:36:54
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/60a632cb295df557713697e92727d551d7345451

Changelog: 

log_reader: strchr(), and some simplifying to make clang happier

Clang's static analyzer thought 'line' might result in a null deref
in the trillian log reader, if there was an empty "(Link: )" section
(temp would be NULL), except that couldn't ever happen, because the data
was *always* \n-terminated, so 'c' is alway non-NULL.

Changes against parent abf0c7744ea5b27942257ab98f6c0dba7480778a

  patched  libpurple/plugins/log_reader.c

-------------- next part --------------
============================================================
--- libpurple/plugins/log_reader.c	258f4e12810db5d465e4a71338ce08b00eb2f8c2
+++ libpurple/plugins/log_reader.c	2f4928de87789c58bb6760beff9e4190a528ce10
@@ -1454,11 +1454,10 @@ static char * trillian_logger_read (Purp
 		const char *footer = NULL;
 		GString *temp = NULL;
 
-		if ((c = strstr(c, "\n")))
-		{
-			*c = '\0';
-			c++;
-		}
+		/* The data is always terminated with a newline (see above) */
+		c = strchr(c, '\n');
+		*c = '\0';
+		c++;
 
 		/* Convert links.
 		 *
@@ -1482,14 +1481,14 @@ static char * trillian_logger_read (Purp
 				char *end_paren;
 				char *space;
 
-				if (!(end_paren = strstr(link, ")")))
+				if (!(end_paren = strchr(link, ')')))
 				{
 					/* Something is not as we expect.  Bail out. */
 					break;
 				}
 
 				if (!temp)
-					temp = g_string_sized_new(c ? (c - 1 - line) : strlen(line));
+					temp = g_string_sized_new(strlen(line));
 
 				g_string_append_len(temp, line, (tmp - line));
 
@@ -1504,7 +1503,7 @@ static char * trillian_logger_read (Purp
 
 				/* The \r is a bit of a hack to keep there from being a \r in
 				 * the link text, which may not matter. */
-				if ((space = strstr(end_paren, " ")) || (space = strstr(end_paren, "\r")))
+				if ((space = strchr(end_paren, ' ')) || (space = strchr(end_paren, '\r')))
 				{
 					g_string_append_len(temp, end_paren + 1, space - end_paren - 1);
 
@@ -1539,7 +1538,7 @@ static char * trillian_logger_read (Purp
 		if (*line == '[') {
 			const char *timestamp;
 
-			if ((timestamp = strstr(line, "]"))) {
+			if ((timestamp = strchr(line, ']'))) {
 				line++;
 				/* TODO: Parse the timestamp and convert it to Purple's format. */
 				g_string_append(formatted, "<font size=\"2\">(");
@@ -1658,7 +1657,7 @@ static char * trillian_logger_read (Purp
 					}
 				}
 			} else {
-				const char *line2 = strstr(line, ":");
+				const char *line2 = strchr(line, ':');
 				if (line2) {
 					const char *acct_name;
 					line2++;
@@ -1828,11 +1827,11 @@ static GList *qip_logger_list(PurpleLogT
 				new_line = c;
 
 				/* find EOL */
-				c = strstr(c, "\n");
+				c = strchr(c, '\n');
 				c++;
 
 				/* Find the last '(' character. */
-				if ((tmp = strstr(c, "\n")) != NULL) {
+				if ((tmp = strchr(c, '\n')) != NULL) {
 					while (*tmp && *tmp != '(') --tmp;
 					c = tmp;
 				} else {
@@ -1904,7 +1903,7 @@ static GList *qip_logger_list(PurpleLogT
 
 		if (*c) {
 			/* find EOF */
-			c = strstr(c, "\n");
+			c = strchr(c, '\n');
 			c++;
 		}
 	}
@@ -1983,13 +1982,13 @@ static char *qip_logger_read(PurpleLog *
 			is_in_message = purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC);
 
 			/* find EOL */
-			c = strstr(c, "\n");
+			c = strchr(c, '\n');
 
 			/* XXX: Do we need buddy_name when we have buddy->alias? */
 			buddy_name = ++c;
 
 			/* Find the last '(' character. */
-			if ((tmp = strstr(c, "\n")) != NULL) {
+			if ((tmp = strchr(c, '\n')) != NULL) {
 				while (*tmp && *tmp != '(') --tmp;
 				c = tmp;
 			} else {
@@ -2042,12 +2041,12 @@ static char *qip_logger_read(PurpleLog *
 					}
 
 					/* find EOF */
-					c = strstr(c, "\n");
+					c = strchr(c, '\n');
 					line = ++c;
 				}
 			}
 		} else {
-			if ((c = strstr(c, "\n")))
+			if ((c = strchr(c, '\n')))
 				*c = '\0';
 
 			if (line[0] != '\n' && line[0] != '\r') {
@@ -2186,7 +2185,7 @@ static GList *amsn_logger_parse_file(cha
 				                  " length = (%d)\n",
 				                  sn, data->path, data->offset, data->length);
 			}
-			c = strstr(c, "\n");
+			c = strchr(c, '\n');
 			c++;
 		}
 
@@ -2342,7 +2341,7 @@ static char *amsn_logger_read(PurpleLog 
 		char *end;
 		char *old_tag;
 		char *tag;
-		end = strstr(start, "\n");
+		end = strchr(start, '\n');
 		if (!end)
 			break;
 		*end = '\0';


More information about the Commits mailing list