propsheet: fix in search of someone to wear dark brown paper bag
Andreas Mohr
andi at rhlx01.fht-esslingen.de
Fri Nov 22 18:27:35 CST 2002
Hello all,
I just lost about 2.5 hours searching for stupid struct "corruption"
in propsheet.c's GetTemplateSize(), resulting in GetTemplateSize()
scanning beyond the memory space allocated for the structs
("darn, why so much garbage ? isn't mem alloc properly zero-mem'ing the
stuff ? why OTOH is windows/dialog.c template parsing output correct ?"
yaddayadda...)
Turned out that someone simply *forgot* to add the cx member
to MyDLGITEMTEMPLATEEX struct !!
Everybody, one, two three: "Doh !".
I also added some comments to windows/dialog.c while I was at it.
Andreas Mohr
Determining best CVS host...
Using CVSROOT :pserver:cvs at rhlx01.fht-esslingen.de:/home/wine
Index: windows/dialog.c
===================================================================
RCS file: /home/wine/wine/windows/dialog.c,v
retrieving revision 1.108
diff -u -r1.108 dialog.c
--- windows/dialog.c 31 Oct 2002 01:04:39 -0000 1.108
+++ windows/dialog.c 22 Nov 2002 23:52:15 -0000
@@ -419,7 +419,7 @@
HWND hwndCtrl, hwndDefButton = 0;
INT items = dlgTemplate->nbItems;
- TRACE(" BEGIN\n" );
+ TRACE(" BEGIN (%d items)\n", items );
while (items--)
{
if (!win32)
@@ -574,15 +574,17 @@
*
* Fill a DLG_TEMPLATE structure from the dialog template, and return
* a pointer to the first control.
+ * See also propsheet.c/GetTemplateSize().
*/
static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
{
const WORD *p = (const WORD *)template;
- result->style = GET_DWORD(p); p += 2;
- if (result->style == 0xffff0001) /* DIALOGEX resource */
+ TRACE("template %p\n", template);
+ if (GET_DWORD(p) == 0xffff0001) /* DIALOGEX resource */
{
result->dialogEx = TRUE;
+ p += 2; /* skip dlgVer & signature */
result->helpId = GET_DWORD(p); p += 2;
result->exStyle = GET_DWORD(p); p += 2;
result->style = GET_DWORD(p); p += 2;
@@ -591,6 +593,7 @@
{
result->dialogEx = FALSE;
result->helpId = 0;
+ result->style = GET_DWORD(p); p += 2;
result->exStyle = GET_DWORD(p); p += 2;
}
result->nbItems = GET_WORD(p); p++;
Index: dlls/comctl32/propsheet.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/propsheet.c,v
retrieving revision 1.74
diff -u -r1.74 propsheet.c
--- dlls/comctl32/propsheet.c 31 Oct 2002 01:04:40 -0000 1.74
+++ dlls/comctl32/propsheet.c 22 Nov 2002 23:52:21 -0000
@@ -56,6 +56,7 @@
DWORD style;
short x;
short y;
+ short cx;
short cy;
DWORD id;
} MyDLGITEMTEMPLATEEX;
@@ -432,7 +433,7 @@
if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
{
- /* DIALOGEX template */
+ /* DLGTEMPLATEEX (not defined in any std. header file) */
p++; /* dlgVer */
p++; /* signature */
@@ -442,7 +443,7 @@
}
else
{
- /* DIALOG template */
+ /* DLGTEMPLATE */
p += 2; /* style */
p += 2; /* ext style */
@@ -1179,6 +1180,7 @@
* Get the size of an in-memory Template
*
*( Based on the code of PROPSHEET_CollectPageInfo)
+ * See also dialog.c/DIALOG_ParseTemplate32().
*/
static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
@@ -1190,8 +1192,9 @@
if (istemplateex)
{
- /* DIALOGEX template */
+ /* DLGTEMPLATEEX (not defined in any std. header file) */
+ TRACE("is DLGTEMPLATEEX\n");
p++; /* dlgVer */
p++; /* signature */
p += 2; /* help ID */
@@ -1200,8 +1203,9 @@
}
else
{
- /* DIALOG template */
+ /* DLGTEMPLATE */
+ TRACE("is DLGTEMPLATE\n");
p += 2; /* style */
p += 2; /* ext style */
}
@@ -1234,7 +1238,7 @@
p++;
break;
case 0xffff:
- p += 2;
+ p += 2; /* 0xffff plus predefined window class ordinal value */
break;
default:
TRACE("class %s\n",debugstr_w((LPCWSTR)p));
@@ -1242,26 +1246,30 @@
break;
}
- /*title */
+ /* title */
TRACE("title %s\n",debugstr_w((LPCWSTR)p));
p += lstrlenW((LPCWSTR)p) + 1;
- /* font, if DS_FONT set */
+ /* font, if DS_SETFONT set */
if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
pTemplate->style)))
{
p+=(istemplateex)?3:1;
TRACE("font %s\n",debugstr_w((LPCWSTR)p));
- p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name*/
+ p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
}
+ /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
+ * that are following the DLGTEMPLATE(EX) data */
TRACE("%d items\n",nrofitems);
while (nrofitems > 0)
{
p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
+ /* skip header */
p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
+ /* check class */
switch ((WORD)*p)
{
case 0x0000:
@@ -1276,6 +1284,8 @@
p += lstrlenW( (LPCWSTR)p ) + 1;
break;
}
+
+ /* check title text */
switch ((WORD)*p)
{
case 0x0000:
@@ -1356,6 +1366,7 @@
if (!temp)
return FALSE;
+ TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
memcpy(temp, pTemplate, resSize);
pTemplate = temp;
@@ -2665,7 +2676,7 @@
INT_PTR CALLBACK
PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
+ TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
hwnd, uMsg, wParam, lParam);
switch (uMsg)
--
Andreas Mohr Stauferstr. 6, D-71272 Renningen, Germany
More information about the wine-patches
mailing list