Win32: don't assume backslashes in path; don't use %z in printf

Thu, 24 Apr 2014 20:28:28 +0200

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Thu, 24 Apr 2014 20:28:28 +0200
changeset 35898
cc46ce85dc0d
parent 35897
8c90f5d9def3
child 35899
ea4adba0d70f

Win32: don't assume backslashes in path; don't use %z in printf

libpurple/dnssrv.c file | annotate | diff | comparison | revisions
pidgin/win32/winpidgin.c file | annotate | diff | comparison | revisions
--- a/libpurple/dnssrv.c	Thu Apr 24 19:00:45 2014 +0200
+++ b/libpurple/dnssrv.c	Thu Apr 24 20:28:28 2014 +0200
@@ -431,8 +431,10 @@
 
 			srvres = g_new0(PurpleSrvResponse, 1);
 			if (strlen(name) > sizeof(srvres->hostname) - 1) {
-				purple_debug_error("dnssrv", "hostname is longer than available buffer ('%s', %zd bytes)!",
-				                   name, strlen(name));
+				purple_debug_error("dnssrv", "hostname is "
+					"longer than available buffer ('%s', %"
+					G_GSIZE_FORMAT " bytes)!",
+					name, strlen(name));
 			}
 			g_strlcpy(srvres->hostname, name, sizeof(srvres->hostname));
 			srvres->pref = pref;
--- a/pidgin/win32/winpidgin.c	Thu Apr 24 19:00:45 2014 +0200
+++ b/pidgin/win32/winpidgin.c	Thu Apr 24 20:28:28 2014 +0200
@@ -157,6 +157,7 @@
 	 * MAX_PATH + 1
 	 */
 	wchar_t set_path[MAX_PATH + 24];
+	wchar_t *fslash, *bslash;
 
 	if (!check_for_gtk(path)) {
 		const wchar_t *winpath = _wgetenv(L"PATH");
@@ -194,7 +195,12 @@
 
 	wcsncpy(tmp_path, path, MAX_PATH);
 	tmp_path[MAX_PATH] = L'\0';
-	wcsrchr(tmp_path, L'\\')[0] = L'\0';
+	bslash = wcsrchr(tmp_path, L'\\');
+	fslash = wcsrchr(tmp_path, L'/');
+	if (bslash && bslash > fslash)
+		bslash[0] = L'\0';
+	else if (fslash && fslash > bslash)
+		fslash[0] = L'\0';
 	/* tmp_path now contains \path\to\Pidgin\Gtk */
 
 	_snwprintf(set_path, sizeof(set_path) / sizeof(wchar_t),

mercurial