PATCH: MultiByteToWideChar - bad argument
Marcus Meissner
marcus at jet.franken.de
Mon Sep 12 02:13:06 CDT 2005
Hi,
MultiByteToWideChar gets character counts as length
arguments for both MB and Wide character string.
A lot of places got this wrong... I audited all of WINE and fixed all
the wrong cases I could spot.
Also at one place nameLen should have been commentLen.
Changelog:
The last argument to MultiByteToWideChar is wide character count
and not the buffer size in bytes.
Fixed all places where it was wrong.
Index: dlls/comctl32/comctl32undoc.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/comctl32undoc.c,v
retrieving revision 1.103
diff -u -r1.103 comctl32undoc.c
--- dlls/comctl32/comctl32undoc.c 6 Sep 2005 11:42:13 -0000 1.103
+++ dlls/comctl32/comctl32undoc.c 12 Sep 2005 07:06:28 -0000
@@ -579,7 +579,7 @@
if (!stringW)
return -1;
- MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
+ MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len/sizeof(WCHAR));
ret = AddMRUData(hList, stringW, len);
Free(stringW);
return ret;
Index: dlls/comctl32/propsheet.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/propsheet.c,v
retrieving revision 1.135
diff -u -r1.135 propsheet.c
--- dlls/comctl32/propsheet.c 30 Aug 2005 10:07:17 -0000 1.135
+++ dlls/comctl32/propsheet.c 12 Sep 2005 07:06:30 -0000
@@ -2161,7 +2161,7 @@
{
WCHAR szTitle[256];
MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
- szTitle, sizeof(szTitle));
+ szTitle, sizeof(szTitle)/sizeof(WCHAR));
PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
}
else
Index: dlls/comctl32/toolbar.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/toolbar.c,v
retrieving revision 1.224
diff -u -r1.224 toolbar.c
--- dlls/comctl32/toolbar.c 30 Aug 2005 10:07:17 -0000 1.224
+++ dlls/comctl32/toolbar.c 12 Sep 2005 07:06:33 -0000
@@ -6492,14 +6492,14 @@
infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
if (infoPtr->pszTooltipText)
{
- MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
+ MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, len+1);
lpnmtdi->lpszText = infoPtr->pszTooltipText;
return 0;
}
}
else if (len > 0)
{
- MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
+ MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, len+1);
return 0;
}
}
Index: dlls/comctl32/treeview.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/treeview.c,v
retrieving revision 1.174
diff -u -r1.174 treeview.c
--- dlls/comctl32/treeview.c 30 Aug 2005 10:07:17 -0000 1.174
+++ dlls/comctl32/treeview.c 12 Sep 2005 07:06:36 -0000
@@ -775,8 +775,8 @@
wineItem->pszText = newText;
MultiByteToWideChar( CP_ACP, 0,
(LPSTR)callback.item.pszText, -1,
- wineItem->pszText, buflen);
- wineItem->cchTextMax = buflen;
+ wineItem->pszText, buflen/sizeof(WCHAR));
+ wineItem->cchTextMax = buflen/sizeof(WCHAR);
}
/* If ReAlloc fails we have nothing to do, but keep original text */
}
@@ -818,8 +818,8 @@
wineItem->pszText = newText;
MultiByteToWideChar( CP_ACP, 0,
(LPSTR)callback.item.pszText, -1,
- wineItem->pszText, buflen);
- wineItem->cchTextMax = buflen;
+ wineItem->pszText, buflen/sizeof(WCHAR));
+ wineItem->cchTextMax = buflen/sizeof(WCHAR);
if (oldText)
Free(oldText);
}
Index: dlls/dbghelp/minidump.c
===================================================================
RCS file: /home/wine/wine/dlls/dbghelp/minidump.c,v
retrieving revision 1.4
diff -u -r1.4 minidump.c
--- dlls/dbghelp/minidump.c 29 Mar 2005 13:14:08 -0000 1.4
+++ dlls/dbghelp/minidump.c 12 Sep 2005 07:06:37 -0000
@@ -407,7 +407,7 @@
if (sizeof(ULONG) + ms->Length > sizeof(tmp))
FIXME("Buffer overflow!!!\n");
MultiByteToWideChar(CP_ACP, 0, dc->module[i].name, -1,
- ms->Buffer, ms->Length);
+ ms->Buffer, ms->Length/sizeof(WCHAR));
if (dc->cb)
{
Index: dlls/dinput/effect_linuxinput.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/effect_linuxinput.c,v
retrieving revision 1.3
diff -u -r1.3 effect_linuxinput.c
--- dlls/dinput/effect_linuxinput.c 9 Sep 2005 09:11:10 -0000 1.3
+++ dlls/dinput/effect_linuxinput.c 12 Sep 2005 07:06:38 -0000
@@ -903,7 +903,7 @@
/* yes, this is windows behavior (print the GUID_Name for name) */
MultiByteToWideChar(CP_ACP, 0, _dump_dinput_GUID(rguid), -1,
- (WCHAR*)&(info->tszName), sizeof(WCHAR) * MAX_PATH);
+ (WCHAR*)&(info->tszName), MAX_PATH);
return DI_OK;
}
Index: dlls/dsound/propset.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/propset.c,v
retrieving revision 1.42
diff -u -r1.42 propset.c
--- dlls/dsound/propset.c 4 Jun 2005 09:38:14 -0000 1.42
+++ dlls/dsound/propset.c 12 Sep 2005 07:06:38 -0000
@@ -1088,8 +1088,8 @@
lstrcpynA(data.DescriptionA, desc.szDesc, sizeof(data.DescriptionA));
lstrcpynA(data.ModuleA, desc.szDrvname, sizeof(data.ModuleA));
- MultiByteToWideChar( CP_ACP, 0, data.DescriptionA, -1, data.DescriptionW, sizeof(data.DescriptionW) );
- MultiByteToWideChar( CP_ACP, 0, data.ModuleA, -1, data.ModuleW, sizeof(data.ModuleW) );
+ MultiByteToWideChar( CP_ACP, 0, data.DescriptionA, -1, data.DescriptionW, sizeof(data.DescriptionW)/sizeof(WCHAR) );
+ MultiByteToWideChar( CP_ACP, 0, data.ModuleA, -1, data.ModuleW, sizeof(data.ModuleW)/sizeof(WCHAR) );
data.Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD)&drv, 0));
@@ -1115,8 +1115,8 @@
lstrcpynA(data.DescriptionA, desc.szDesc, sizeof(data.DescriptionA));
lstrcpynA(data.ModuleA, desc.szDrvname, sizeof(data.ModuleA));
- MultiByteToWideChar( CP_ACP, 0, data.DescriptionA, -1, data.DescriptionW, sizeof(data.DescriptionW) );
- MultiByteToWideChar( CP_ACP, 0, data.ModuleA, -1, data.ModuleW, sizeof(data.ModuleW) );
+ MultiByteToWideChar( CP_ACP, 0, data.DescriptionA, -1, data.DescriptionW, sizeof(data.DescriptionW)/sizeof(WCHAR) );
+ MultiByteToWideChar( CP_ACP, 0, data.ModuleA, -1, data.ModuleW, sizeof(data.ModuleW)/sizeof(WCHAR) );
data.Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
err = mmErr(waveInMessage((HWAVEIN)wid, DRV_QUERYDSOUNDIFACE, (DWORD)&drv, 0));
Index: dlls/gdi/freetype.c
===================================================================
RCS file: /home/wine/wine/dlls/gdi/freetype.c,v
retrieving revision 1.98
diff -u -r1.98 freetype.c
--- dlls/gdi/freetype.c 8 Sep 2005 12:40:20 -0000 1.98
+++ dlls/gdi/freetype.c 12 Sep 2005 07:06:40 -0000
@@ -848,7 +848,7 @@
&dlen) == ERROR_SUCCESS) {
TRACE("Got %s=%s\n", debugstr_a(value), debugstr_a(data));
/* "NewName"="Oldname" */
- if(!MultiByteToWideChar(CP_ACP, 0, data, -1, old_nameW, sizeof(old_nameW)))
+ if(!MultiByteToWideChar(CP_ACP, 0, data, -1, old_nameW, sizeof(old_nameW)/sizeof(WCHAR)))
break;
/* Find the old family and hence all of the font files
@@ -3075,7 +3075,7 @@
* sizeof(WCHAR);
style_nameW = HeapAlloc(GetProcessHeap(), 0, lensty);
MultiByteToWideChar(CP_ACP, 0, ft_face->style_name, -1,
- style_nameW, lensty);
+ style_nameW, lensty/sizeof(WCHAR));
/* These names should be read from the TT name table */
Index: dlls/oleaut32/tests/vartest.c
===================================================================
RCS file: /home/wine/wine/dlls/oleaut32/tests/vartest.c,v
retrieving revision 1.45
diff -u -r1.45 vartest.c
--- dlls/oleaut32/tests/vartest.c 23 Aug 2005 09:33:37 -0000 1.45
+++ dlls/oleaut32/tests/vartest.c 12 Sep 2005 07:06:48 -0000
@@ -625,7 +625,7 @@
/* Macros for converting and testing the result of VarParseNumFromStr */
#define FAILDIG 255
-#define CONVERTN(str,dig,flags) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
+#define CONVERTN(str,dig,flags) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
memset(rgb, FAILDIG, sizeof(rgb)); memset(&np,-1,sizeof(np)); np.cDig = dig; np.dwInFlags = flags; \
hres = pVarParseNumFromStr(buff,lcid,LOCALE_NOUSEROVERRIDE,&np,rgb)
#define CONVERT(str,flags) CONVERTN(str,sizeof(rgb),flags)
Index: dlls/oleaut32/tests/vartype.c
===================================================================
RCS file: /home/wine/wine/dlls/oleaut32/tests/vartype.c,v
retrieving revision 1.31
diff -u -r1.31 vartype.c
--- dlls/oleaut32/tests/vartype.c 9 Sep 2005 15:01:17 -0000 1.31
+++ dlls/oleaut32/tests/vartype.c 12 Sep 2005 07:06:50 -0000
@@ -121,7 +121,7 @@
#define CONVERT_STR(func,str,flags) \
SetLastError(0); \
- if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
+ if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
hres = p##func(str ? buff : NULL,in,flags,&out)
#define COPYTEST(val, vt, srcval, dstval, srcref, dstref, fs) do { \
@@ -3249,7 +3249,7 @@
#define DFS(str) \
buff[0] = '\0'; out = 0.0; \
- if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)); \
+ if (str) MultiByteToWideChar(CP_ACP,0,str,-1,buff,sizeof(buff)/sizeof(WCHAR)); \
hres = pVarDateFromStr(str ? buff : NULL,lcid,LOCALE_NOUSEROVERRIDE,&out)
#define MKRELDATE(day,mth) st.wMonth = mth; st.wDay = day; \
Index: dlls/riched20/reader.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/reader.c,v
retrieving revision 1.16
diff -u -r1.16 reader.c
--- dlls/riched20/reader.c 23 Aug 2005 18:16:15 -0000 1.16
+++ dlls/riched20/reader.c 12 Sep 2005 07:06:52 -0000
@@ -2755,7 +2755,7 @@
int length;
length = MultiByteToWideChar(info->codePage, 0, info->cpOutputBuffer,
- info->dwCPOutputCount, buffer, bufferMax);
+ info->dwCPOutputCount, buffer, bufferMax/sizeof(WCHAR));
info->dwCPOutputCount = 0;
RTFPutUnicodeString(info, buffer, length);
Index: dlls/riched20/style.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/style.c,v
retrieving revision 1.7
diff -u -r1.7 style.c
--- dlls/riched20/style.c 24 Jul 2005 16:17:43 -0000 1.7
+++ dlls/riched20/style.c 12 Sep 2005 07:06:52 -0000
@@ -52,7 +52,7 @@
CopyMemory(to, f, sizeof(CHARFORMATA)-sizeof(f->szFaceName));
/* convert face name */
if (f->dwMask & CFM_FACE)
- MultiByteToWideChar(0, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName));
+ MultiByteToWideChar(0, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
/* copy the rest of the 2A structure to 2W */
CopyMemory(1+((CHARFORMATW *)to), f+1, sizeof(CHARFORMAT2A)-sizeof(CHARFORMATA));
to->cbSize = sizeof(CHARFORMAT2W);
Index: dlls/secur32/thunks.c
===================================================================
RCS file: /home/wine/wine/dlls/secur32/thunks.c,v
retrieving revision 1.1
diff -u -r1.1 thunks.c
--- dlls/secur32/thunks.c 2 Mar 2004 04:57:35 -0000 1.1
+++ dlls/secur32/thunks.c 12 Sep 2005 07:06:53 -0000
@@ -620,7 +620,7 @@
{
ret->Comment = nextString;
MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1, nextString,
- nameLen);
+ commentLen);
}
else
ret->Comment = NULL;
Index: dlls/setupapi/parser.c
===================================================================
RCS file: /home/wine/wine/dlls/setupapi/parser.c,v
retrieving revision 1.19
diff -u -r1.19 parser.c
--- dlls/setupapi/parser.c 15 Aug 2005 09:43:28 -0000 1.19
+++ dlls/setupapi/parser.c 12 Sep 2005 07:06:53 -0000
@@ -951,8 +951,7 @@
WCHAR *new_buff = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) );
if (new_buff)
{
- DWORD len = MultiByteToWideChar( CP_ACP, 0, buffer, size, new_buff,
- size * sizeof(WCHAR) );
+ DWORD len = MultiByteToWideChar( CP_ACP, 0, buffer, size, new_buff, size );
err = parse_buffer( file, new_buff, new_buff + len, error_line );
HeapFree( GetProcessHeap(), 0, new_buff );
}
Index: dlls/shlwapi/reg.c
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/reg.c,v
retrieving revision 1.62
diff -u -r1.62 reg.c
--- dlls/shlwapi/reg.c 28 Jul 2005 10:18:24 -0000 1.62
+++ dlls/shlwapi/reg.c 12 Sep 2005 07:06:54 -0000
@@ -134,7 +134,7 @@
/* Create internal HUSKEY */
hKey = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*hKey));
- lstrcpynW(hKey->lpszPath, Path, sizeof(hKey->lpszPath));
+ lstrcpynW(hKey->lpszPath, Path, sizeof(hKey->lpszPath)/sizeof(WCHAR));
if (hRelativeUSKey)
{
Index: dlls/shlwapi/string.c
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/string.c,v
retrieving revision 1.56
diff -u -r1.56 string.c
--- dlls/shlwapi/string.c 11 Aug 2005 18:35:15 -0000 1.56
+++ dlls/shlwapi/string.c 12 Sep 2005 07:06:56 -0000
@@ -1810,7 +1810,7 @@
if (*lppszDest)
{
- MultiByteToWideChar(0, 0, lpszStr, -1, *lppszDest, len);
+ MultiByteToWideChar(0, 0, lpszStr, -1, *lppszDest, len/sizeof(WCHAR));
hRet = S_OK;
}
else
Index: dlls/winmm/message16.c
===================================================================
RCS file: /home/wine/wine/dlls/winmm/message16.c,v
retrieving revision 1.15
diff -u -r1.15 message16.c
--- dlls/winmm/message16.c 18 Aug 2005 10:53:58 -0000 1.15
+++ dlls/winmm/message16.c 12 Sep 2005 07:06:57 -0000
@@ -3452,7 +3452,7 @@
UnMapLS( lParam );
if (msip16) {
MultiByteToWideChar(CP_ACP, 0, MapSL(msip16->lpstrReturn), msip16->dwRetSize,
- msip32w->lpstrReturn, msip32w->dwRetSize);
+ msip32w->lpstrReturn, msip32w->dwRetSize/sizeof(WCHAR));
UnMapLS( msip16->lpstrReturn );
HeapFree( GetProcessHeap(), 0, MapSL(msip16->lpstrReturn) );
HeapFree( GetProcessHeap(), 0, (char*)msip16 - sizeof(LPMCI_SYSINFO_PARMSW) );
Index: dlls/winmm/winmm.c
===================================================================
RCS file: /home/wine/wine/dlls/winmm/winmm.c,v
retrieving revision 1.56
diff -u -r1.56 winmm.c
--- dlls/winmm/winmm.c 9 Sep 2005 10:19:44 -0000 1.56
+++ dlls/winmm/winmm.c 12 Sep 2005 07:06:59 -0000
@@ -603,7 +603,7 @@
mliW.Target.wMid = lpmliA->Target.wMid;
mliW.Target.wPid = lpmliA->Target.wPid;
mliW.Target.vDriverVersion = lpmliA->Target.vDriverVersion;
- MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname));
+ MultiByteToWideChar( CP_ACP, 0, lpmliA->Target.szPname, -1, mliW.Target.szPname, sizeof(mliW.Target.szPname)/sizeof(WCHAR));
break;
default:
WARN("Unsupported fdwControls=0x%08lx\n", fdwInfo);
Index: dlls/winsock/socket.c
===================================================================
RCS file: /home/wine/wine/dlls/winsock/socket.c,v
retrieving revision 1.189
diff -u -r1.189 socket.c
--- dlls/winsock/socket.c 27 Aug 2005 09:20:24 -0000 1.189
+++ dlls/winsock/socket.c 12 Sep 2005 07:07:01 -0000
@@ -3082,7 +3082,7 @@
memcpy(&info, lpProtocolInfo, FIELD_OFFSET(WSAPROTOCOL_INFOW, szProtocol));
len = MultiByteToWideChar(CP_ACP, 0, lpProtocolInfo->szProtocol, -1,
- info.szProtocol, WSAPROTOCOL_LEN * sizeof(WCHAR) + 1);
+ info.szProtocol, WSAPROTOCOL_LEN + 1);
if (!len)
{
Index: dlls/x11drv/xim.c
===================================================================
RCS file: /home/wine/wine/dlls/x11drv/xim.c,v
retrieving revision 1.6
diff -u -r1.6 xim.c
--- dlls/x11drv/xim.c 17 Jun 2005 10:11:37 -0000 1.6
+++ dlls/x11drv/xim.c 12 Sep 2005 07:07:02 -0000
@@ -224,7 +224,7 @@
WCHAR wcOutput[64];
HWND focus;
- dwOutput = MultiByteToWideChar(CP_UNIXCP, 0, str, count, wcOutput, sizeof(wcOutput));
+ dwOutput = MultiByteToWideChar(CP_UNIXCP, 0, str, count, wcOutput, sizeof(wcOutput)/sizeof(WCHAR));
if (pImmAssociateContext && (focus = GetFocus()))
pImmAssociateContext(focus,root_context);
Index: programs/winemenubuilder/winemenubuilder.c
===================================================================
RCS file: /home/wine/wine/programs/winemenubuilder/winemenubuilder.c,v
retrieving revision 1.33
diff -u -r1.33 winemenubuilder.c
--- programs/winemenubuilder/winemenubuilder.c 22 Aug 2005 09:17:25 -0000 1.33
+++ programs/winemenubuilder/winemenubuilder.c 12 Sep 2005 07:07:08 -0000
@@ -994,7 +994,7 @@
{
WCHAR link[MAX_PATH];
- MultiByteToWideChar( CP_ACP, 0, token, -1, link, sizeof(link) );
+ MultiByteToWideChar( CP_ACP, 0, token, -1, link, sizeof(link)/sizeof(WCHAR) );
if( !Process_Link( link, bAgain ) )
{
WINE_ERR( "failed to build menu item for %s\n",token);
More information about the wine-patches
mailing list