pidgin: 6eb94bb9: Get rid of a few unnecessary strlen/g_sn..

sadrul at pidgin.im sadrul at pidgin.im
Mon Jul 12 11:12:59 EDT 2010


----------------------------------------------------------------------
Revision: 6eb94bb98b242b76b07fe78fe89d136b9201d6f1
Parent:   5bd75cb6ae49344ece9ab07201c5af0bf2c9930c
Author:   sadrul at pidgin.im
Date:     07/12/10 11:13:31
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/6eb94bb98b242b76b07fe78fe89d136b9201d6f1

Changelog: 

Get rid of a few unnecessary strlen/g_snprintf's.

This change also includes HanzZ's patch (slightly modified) to fix a
valgrind error:

 Conditional jump or move depends on uninitialised value(s)
    at 0x4C28029: strlen (mc_replace_strmem.c:242)
    by 0x54E5821: g_strdup (in /usr/lib/libglib-2.0.so.0.2000.1)
    by 0x520B276: purple_url_parse (in /usr/lib/libpurple.so.0.7.1)
    by 0x520BBE1: (within /usr/lib/libpurple.so.0.7.1)
    by 0x471330: io_invoke(_GIOChannel*, GIOCondition, void*) (geventloop.cpp:51)
    by 0x54C5209: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.2000.1)
    by 0x54C88DF: (within /usr/lib/libglib-2.0.so.0.2000.1)
    by 0x54C8DAC: g_main_loop_run (in /usr/lib/libglib-2.0.so.0.2000.1)
    by 0x482BEE: GlooxMessageHandler::GlooxMessageHandler(std::string const&) (main.cpp:1016)
    by 0x4830E3: main (main.cpp:1996)


Changes against parent 5bd75cb6ae49344ece9ab07201c5af0bf2c9930c

  patched  libpurple/util.c

-------------- next part --------------
============================================================
--- libpurple/util.c	40d477227df1569d24e08d81df631fca3e531c6b
+++ libpurple/util.c	15a81fd6f0c41d66d2a0a7199314d1920fa4d347
@@ -3423,7 +3423,7 @@ purple_url_parse(const char *url, char *
 			   char **ret_path, char **ret_user, char **ret_passwd)
 {
 	gboolean is_https = FALSE;
-	char scan_info[255];
+	const char * scan_info;
 	char port_str[6];
 	int f;
 	const char *at, *slash;
@@ -3431,12 +3431,13 @@ purple_url_parse(const char *url, char *
 	char host[256], path[256], user[256], passwd[256];
 	int port = 0;
 	/* hyphen at end includes it in control set */
-	static const char addr_ctrl[] = "A-Za-z0-9.-";
-	static const char port_ctrl[] = "0-9";
-	static const char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-";
-	static const char user_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
-	static const char passwd_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
 
+#define ADDR_CTRL "A-Za-z0-9.-"
+#define PORT_CTRL "0-9"
+#define PAGE_CTRL "A-Za-z0-9.~_/:*!@&%%?=+^-"
+#define USER_CTRL "A-Za-z0-9.~_/*!&%%?=+^-"
+#define PASSWD_CTRL "A-Za-z0-9.~_/*!&%%?=+^-"
+
 	g_return_val_if_fail(url != NULL, FALSE);
 
 	if ((turl = purple_strcasestr(url, "http://")) != NULL)
@@ -3455,37 +3456,32 @@ purple_url_parse(const char *url, char *
 	/* Only care about @ char BEFORE the first / */
 	at = strchr(url, '@');
 	slash = strchr(url, '/');
-	if ((at != NULL) &&
-			(((slash != NULL) && (strlen(at) > strlen(slash))) ||
-			(slash == NULL))) {
-		g_snprintf(scan_info, sizeof(scan_info),
-					"%%255[%s]:%%255[%s]^@", user_ctrl, passwd_ctrl);
+	f = 0;
+	if (at && (!slash || at < slash)) {
+		scan_info = "%255[" USER_CTRL "]:%255[" PASSWD_CTRL "]^@";
 		f = sscanf(url, scan_info, user, passwd);
 
-		if (f ==1 ) {
+		if (f == 1) {
 			/* No passwd, possibly just username supplied */
-			g_snprintf(scan_info, sizeof(scan_info),
-						"%%255[%s]^@", user_ctrl);
+			scan_info = "%255[" USER_CTRL "]^@";
 			f = sscanf(url, scan_info, user);
-			*passwd = '\0';
 		}
 
 		url = at+1; /* move pointer after the @ char */
-	} else {
+	}
+
+	if (f < 1) {
 		*user = '\0';
 		*passwd = '\0';
-	}
+	} else if (f == 1)
+		*passwd = '\0';
 
-	g_snprintf(scan_info, sizeof(scan_info),
-			   "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, page_ctrl);
-
+	scan_info = "%255[" ADDR_CTRL "]:%5[" PORT_CTRL "]/%255[" PAGE_CTRL "]";
 	f = sscanf(url, scan_info, host, port_str, path);
 
 	if (f == 1)
 	{
-		g_snprintf(scan_info, sizeof(scan_info),
-				   "%%255[%s]/%%255[%s]",
-				   addr_ctrl, page_ctrl);
+		scan_info = "%255[" ADDR_CTRL "]/%255[" PAGE_CTRL "]";
 		f = sscanf(url, scan_info, host, path);
 		/* Use the default port */
 		if (is_https)
@@ -3509,6 +3505,12 @@ purple_url_parse(const char *url, char *
 	if (ret_passwd != NULL) *ret_passwd = g_strdup(passwd);
 
 	return ((*host != '\0') ? TRUE : FALSE);
+
+#undef ADDR_CTRL
+#undef PORT_CTRL
+#undef PAGE_CTRL
+#undef USER_CTRL
+#undef PASSWD_CTRL
 }
 
 /**


More information about the Commits mailing list