/pidgin/main: 562961da7c0d: Avoid unnecessary sizeof(char); it m...

Daniel Atallah datallah at pidgin.im
Mon Sep 10 23:16:34 EDT 2012


Changeset: 562961da7c0d650732c69d20a7725bfba0a2efe0
Author:	 Daniel Atallah <datallah at pidgin.im>
Date:	 2012-09-10 23:15 -0400
Branch:	 release-2.x.y
URL: http://hg.pidgin.im/pidgin/main/rev/562961da7c0d

Description:

Avoid unnecessary sizeof(char); it must always be 1

 * If it wasn't always 1, there would be a bug in this (line ~705)
 * WideCharToMultiByte returns the size in bytes, not chars, so this was also wrong in that respect.

diffstat:

 pidgin/win32/winpidgin.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (52 lines):

diff --git a/pidgin/win32/winpidgin.c b/pidgin/win32/winpidgin.c
--- a/pidgin/win32/winpidgin.c
+++ b/pidgin/win32/winpidgin.c
@@ -557,7 +557,7 @@ static void handle_protocol(wchar_t *cmd
 	len = WideCharToMultiByte(CP_UTF8, 0, tmp1,
 			wlen, NULL, 0, NULL, NULL);
 	if (len) {
-		utf8msg = malloc(len * sizeof(char));
+		utf8msg = malloc(len);
 		len = WideCharToMultiByte(CP_UTF8, 0, tmp1,
 			wlen, utf8msg, len, NULL, NULL);
 	}
@@ -702,7 +702,7 @@ WinMain (struct HINSTANCE__ *hInstance, 
 				 * again when it initializes) */
 				MySetLogFile = (LPFNSETLOGFILE) GetProcAddress(hmod, "SetLogFile");
 				if (MySetLogFile) {
-					if (GetTempPathA(sizeof(debug_dir) * sizeof(char), debug_dir) != 0) {
+					if (GetTempPathA(sizeof(debug_dir), debug_dir) != 0) {
 						strcat(debug_dir, "pidgin.RPT");
 						printf(" Setting exchndl.dll LogFile to %s\n",
 							debug_dir);
@@ -719,7 +719,7 @@ WinMain (struct HINSTANCE__ *hInstance, 
 					i = WideCharToMultiByte(CP_ACP, 0, pidgin_dir,
 						-1, NULL, 0, NULL, NULL);
 					if (i != 0) {
-						pidgin_dir_ansi = malloc(i * sizeof(char));
+						pidgin_dir_ansi = malloc(i);
 						i = WideCharToMultiByte(CP_ACP, 0, pidgin_dir,
 							-1, pidgin_dir_ansi, i, NULL, NULL);
 						if (i == 0) {
@@ -728,10 +728,10 @@ WinMain (struct HINSTANCE__ *hInstance, 
 						}
 					}
 					if (pidgin_dir_ansi != NULL) {
-						_snprintf(debug_dir, sizeof(debug_dir) / sizeof(char),
+						_snprintf(debug_dir, sizeof(debug_dir),
 							"%s\\pidgin-%s-dbgsym",
 							pidgin_dir_ansi,  VERSION);
-						debug_dir[sizeof(debug_dir) / sizeof(char) - 1] = '\0';
+						debug_dir[sizeof(debug_dir) - 1] = '\0';
 						printf(" Setting exchndl.dll DebugInfoDir to %s\n",
 							debug_dir);
 						MySetLogFile(debug_dir);
@@ -812,7 +812,7 @@ WinMain (struct HINSTANCE__ *hInstance, 
 			int len = WideCharToMultiByte(CP_UTF8, 0, szArglist[i],
 				-1, NULL, 0, NULL, NULL);
 			if (len != 0) {
-				char *arg = malloc(len * sizeof(char));
+				char *arg = malloc(len);
 				len = WideCharToMultiByte(CP_UTF8, 0, szArglist[i],
 					-1, arg, len, NULL, NULL);
 				if (len != 0) {



More information about the Commits mailing list