[ros-diffs] [gbrunmar] 33503: Hopefully fixes bug #1110. Requested fixed by amine48rz. See issue #1110 for more details.

gbrunmar at svn.reactos.org gbrunmar at svn.reactos.org
Tue May 13 22:14:31 CEST 2008


Author: gbrunmar
Date: Tue May 13 15:14:30 2008
New Revision: 33503

URL: http://svn.reactos.org/svn/reactos?rev=33503&view=rev
Log:
Hopefully fixes bug #1110. Requested fixed by amine48rz.
See issue #1110 for more details.

Modified:
    trunk/reactos/dll/win32/user32/controls/combo.c
    trunk/reactos/dll/win32/user32/controls/edit.c
    trunk/reactos/dll/win32/user32/controls/listbox.c
    trunk/reactos/dll/win32/user32/misc/exticon.c
    trunk/reactos/dll/win32/user32/misc/wsprintf.c
    trunk/reactos/dll/win32/user32/windows/dialog.c
    trunk/reactos/dll/win32/user32/windows/mdi.c

Modified: trunk/reactos/dll/win32/user32/controls/combo.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/combo.c?rev=33503&r1=33502&r2=33503&view=diff
==============================================================================
--- trunk/reactos/dll/win32/user32/controls/combo.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/controls/combo.c [iso-8859-1] Tue May 13 15:14:30 2008
@@ -1847,7 +1847,8 @@
 
     len = strlen(str);
     ret = HeapAlloc(GetProcessHeap(), 0, len + 1);
-    memcpy(ret, str, len + 1);
+    if (ret != NULL)
+        memcpy(ret, str, len + 1);
     return ret;
 }
 

Modified: trunk/reactos/dll/win32/user32/controls/edit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/edit.c?rev=33503&r1=33502&r2=33503&view=diff
==============================================================================
--- trunk/reactos/dll/win32/user32/controls/edit.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/controls/edit.c [iso-8859-1] Tue May 13 15:14:30 2008
@@ -656,7 +656,7 @@
 		    LPSTR textA = (LPSTR)lParam;
 		    INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
 		    if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
-			MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW);
+			    MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW);
 		}
 
 		EDIT_EM_ReplaceSel(es, (BOOL)wParam, textW, TRUE, TRUE);
@@ -930,9 +930,9 @@
 		    LPWSTR nameW = NULL;
 		    if(nameA)
 		    {
-			INT countW = MultiByteToWideChar(CP_ACP, 0, nameA, -1, NULL, 0);
-			if((nameW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
-			    MultiByteToWideChar(CP_ACP, 0, nameA, -1, nameW, countW);
+			    INT countW = MultiByteToWideChar(CP_ACP, 0, nameA, -1, NULL, 0);
+			    if((nameW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
+			        MultiByteToWideChar(CP_ACP, 0, nameA, -1, nameW, countW);
 		    }
 		    result = EDIT_WM_Create(es, nameW);
 		    HeapFree(GetProcessHeap(), 0, nameW);
@@ -1222,6 +1222,8 @@
 				/* The buffer has been expanded, create a new line and
 				   insert it into the link list */
 				LINEDEF *new_line = HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF));
+                if (new_line == NULL)
+                    break;
 				new_line->next = previous_line->next;
 				previous_line->next = new_line;
 				current_line = new_line;
@@ -1517,6 +1519,8 @@
 
 		countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL);
 		textA = HeapAlloc(GetProcessHeap(), 0, countA);
+        if (textA == NULL)
+            return 0;
 		WideCharToMultiByte(CP_ACP, 0, es->text + start, count, textA, countA, NULL, NULL);
 		TRACE_(relay)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
 			es->word_break_proc, debugstr_an(textA, countA), index, countA, action);
@@ -1723,6 +1727,8 @@
 	if (es->style & ES_PASSWORD) {
 		INT len = get_text_length(es);
 		LPWSTR text = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
+        if (text == NULL)
+            return NULL;
 		text[len] = '\0';
 		while(len) text[--len] = es->password_char;
 		return text;
@@ -3958,6 +3964,11 @@
 		es->tabs = NULL;
 	else {
 		es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
+        if (es->tabs == NULL)
+        {
+            es->tabs_count = 0;
+            return FALSE;
+        }
 		memcpy(es->tabs, tabs, count * sizeof(INT));
 	}
 	return TRUE;
@@ -4051,6 +4062,8 @@
 	ulength = strlenW(es->undo_text);
 
 	utext = HeapAlloc(GetProcessHeap(), 0, (ulength + 1) * sizeof(WCHAR));
+    if (utext == NULL)
+        return FALSE;
 
 	strcpyW(utext, es->undo_text);
 

Modified: trunk/reactos/dll/win32/user32/controls/listbox.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/controls/listbox.c?rev=33503&r1=33502&r2=33503&view=diff
==============================================================================
--- trunk/reactos/dll/win32/user32/controls/listbox.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/controls/listbox.c [iso-8859-1] Tue May 13 15:14:30 2008
@@ -1620,8 +1620,15 @@
         /* We need to grow the array */
         max_items += LB_ARRAY_GRANULARITY;
 	if (descr->items)
+    {
     	    item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
                                   max_items * sizeof(LB_ITEMDATA) );
+            if (!item)
+            {
+                SEND_NOTIFICATION( descr, LBN_ERRSPACE );
+                return LB_ERRSPACE;
+            }
+    }
 	else
 	    item = HeapAlloc( GetProcessHeap(), 0,
                                   max_items * sizeof(LB_ITEMDATA) );

Modified: trunk/reactos/dll/win32/user32/misc/exticon.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/misc/exticon.c?rev=33503&r1=33502&r2=33503&view=diff
==============================================================================
--- trunk/reactos/dll/win32/user32/misc/exticon.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/misc/exticon.c [iso-8859-1] Tue May 13 15:14:30 2008
@@ -630,6 +630,8 @@
     UINT ret;
     INT len = MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, NULL, 0);
     LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+    if (lpwstrFile == NULL)
+        return 0;
 
     MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, lpwstrFile, len);
     ret = PrivateExtractIconsW(lpwstrFile, nIndex, sizeX, sizeY, phicon, piconid, nIcons, flags);
@@ -709,6 +711,8 @@
 	UINT ret;
 	INT len = MultiByteToWideChar(CP_ACP, 0, lpstrFile, -1, NULL, 0);
 	LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+    if (lpwstrFile == NULL)
+        return 0;
 
 	TRACE("%s %d %p %p %d\n", lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons);
 

Modified: trunk/reactos/dll/win32/user32/misc/wsprintf.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/misc/wsprintf.c?rev=33503&r1=33502&r2=33503&view=diff
==============================================================================
--- trunk/reactos/dll/win32/user32/misc/wsprintf.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/misc/wsprintf.c [iso-8859-1] Tue May 13 15:14:30 2008
@@ -553,7 +553,10 @@
 	}
 	if (Allocate)
 	{
-		*MBString = RtlAllocateHeap(GetProcessHeap(), 0, MBSize);
+		LPSTR SafeString = RtlAllocateHeap(GetProcessHeap(), 0, MBSize);
+        if (SafeString == NULL)
+            return 0;
+        *MBString = SafeString;
 	}
 	if (CodePage == 0)
 	{
@@ -585,7 +588,10 @@
 	}
 	if (Allocate)
 	{
-		*UnicodeString = RtlAllocateHeap(GetProcessHeap(), 0, UnicodeSize);
+		LPWSTR SafeString = RtlAllocateHeap(GetProcessHeap(), 0, UnicodeSize);
+        if (SafeString == NULL)
+            return 0;
+        *UnicodeString = SafeString;
 	}
 	UnicodeSize *= sizeof(WCHAR);
 	if (CodePage == 0)

Modified: trunk/reactos/dll/win32/user32/windows/dialog.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/windows/dialog.c?rev=33503&r1=33502&r2=33503&view=diff
==============================================================================
--- trunk/reactos/dll/win32/user32/windows/dialog.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/windows/dialog.c [iso-8859-1] Tue May 13 15:14:30 2008
@@ -244,8 +244,15 @@
     if (GET_WORD(p) == 0xffff)  /* Is it an integer id? */
     {
         info->windowName = HeapAlloc( GetProcessHeap(), 0, sizeof(L"#65535") );
-        swprintf((LPWSTR)info->windowName, L"#%d", GET_WORD(p + 1));
-        info->windowNameFree = TRUE;
+        if (info->windowName != NULL)
+        {
+            swprintf((LPWSTR)info->windowName, L"#%d", GET_WORD(p + 1));
+            info->windowNameFree = TRUE;
+        }
+        else
+        {
+            info->windowNameFree = FALSE;
+        }
         p += 2;
     }
     else
@@ -280,7 +287,7 @@
     HWND hwndCtrl, hwndDefButton = 0;
     INT items = dlgTemplate->nbItems;
 
-    if (!(dlgInfo = GETDLGINFO(hwnd))) return -1;
+    if (!(dlgInfo = GETDLGINFO(hwnd))) return FALSE;
 
     while (items--)
     {
@@ -313,22 +320,30 @@
             {
                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.className, -1, NULL, 0, NULL, NULL );
                 class = HeapAlloc( GetProcessHeap(), 0, len );
-                WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
+                if (class != NULL)
+                    WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
             }
             if (HIWORD(caption))
             {
                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, NULL, 0, NULL, NULL );
                 caption = HeapAlloc( GetProcessHeap(), 0, len );
-                WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, caption, len, NULL, NULL );
+                if (caption != NULL)
+                    WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, caption, len, NULL, NULL );
             }
-            hwndCtrl = CreateWindowExA( info.exStyle | WS_EX_NOPARENTNOTIFY,
-                                        class, caption, info.style | WS_CHILD,
-                                        MulDiv(info.x, dlgInfo->xBaseUnit, 4),
-                                        MulDiv(info.y, dlgInfo->yBaseUnit, 8),
-                                        MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
-                                        MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
-                                        hwnd, (HMENU)info.id,
-                                        hInst, (LPVOID)info.data );
+
+            if (class != NULL && caption != NULL)
+            {
+                hwndCtrl = CreateWindowExA( info.exStyle | WS_EX_NOPARENTNOTIFY,
+                                            class, caption, info.style | WS_CHILD,
+                                            MulDiv(info.x, dlgInfo->xBaseUnit, 4),
+                                            MulDiv(info.y, dlgInfo->yBaseUnit, 8),
+                                            MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
+                                            MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
+                                            hwnd, (HMENU)info.id,
+                                            hInst, (LPVOID)info.data );
+            }
+            else
+                hwndCtrl = NULL;
             if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
             if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
         }
@@ -750,19 +765,27 @@
         {
             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
             class = HeapAlloc( GetProcessHeap(), 0, len );
-            WideCharToMultiByte( CP_ACP, 0, template.className, -1, class, len, NULL, NULL );
+            if (class != NULL)
+                WideCharToMultiByte( CP_ACP, 0, template.className, -1, class, len, NULL, NULL );
         }
         if (HIWORD(caption))
         {
             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
             caption = HeapAlloc( GetProcessHeap(), 0, len );
-            WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption, len, NULL, NULL );
-        }
-        hwnd = User32CreateWindowEx(template.exStyle, class, caption,
-                                    template.style & ~WS_VISIBLE,
-                                    rect.left, rect.top, rect.right, rect.bottom,
-                                    owner, hMenu, hInst, NULL,
-                                    FALSE);
+            if (caption != NULL)
+                WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption, len, NULL, NULL );
+        }
+
+        if (class != NULL && caption != NULL)
+        {
+            hwnd = User32CreateWindowEx(template.exStyle, class, caption,
+                                        template.style & ~WS_VISIBLE,
+                                        rect.left, rect.top, rect.right, rect.bottom,
+                                        owner, hMenu, hInst, NULL,
+                                        FALSE);
+        }
+        else
+            hwnd = NULL;
         if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
         if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
     }
@@ -1272,6 +1295,8 @@
     {
         INT ret, len = MultiByteToWideChar( CP_ACP, 0, spec, -1, NULL, 0 );
         LPWSTR specW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        if (specW == NULL)
+            return FALSE;
         MultiByteToWideChar( CP_ACP, 0, spec, -1, specW, len );
         ret = DIALOG_DlgDirListW( hDlg, specW, idLBox, idStatic, attrib, combo );
         WideCharToMultiByte( CP_ACP, 0, specW, -1, spec, 0x7fffffff, NULL, NULL );

Modified: trunk/reactos/dll/win32/user32/windows/mdi.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/windows/mdi.c?rev=33503&r1=33502&r2=33503&view=diff
==============================================================================
--- trunk/reactos/dll/win32/user32/windows/mdi.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/user32/windows/mdi.c [iso-8859-1] Tue May 13 15:14:30 2008
@@ -592,11 +592,22 @@
         if (ci->child[i] == child)
         {
             HWND *new_child = HeapAlloc(GetProcessHeap(), 0, (ci->nActiveChildren - 1) * sizeof(HWND));
-            memcpy(new_child, ci->child, i * sizeof(HWND));
-            if (i + 1 < ci->nActiveChildren)
-                memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
-            HeapFree(GetProcessHeap(), 0, ci->child);
-            ci->child = new_child;
+            if (new_child != NULL)
+            {
+                memcpy(new_child, ci->child, i * sizeof(HWND));
+                if (i + 1 < ci->nActiveChildren)
+                    memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
+                HeapFree(GetProcessHeap(), 0, ci->child);
+                ci->child = new_child;
+            }
+            else
+            {
+                UINT c;
+                for (c = i; c < ci->nActiveChildren - 1; c++)
+                {
+                    ci->child[c] = ci->child[c+1];
+                }
+            }
 
             ci->nActiveChildren--;
             break;
@@ -1248,15 +1259,17 @@
         case WM_CREATE:
             if (GetWindowLongW((HWND)lParam, GWL_EXSTYLE) & WS_EX_MDICHILD)
             {
-                ci->nTotalCreated++;
-                ci->nActiveChildren++;
-
                 if (!ci->child)
                     ci->child = HeapAlloc(GetProcessHeap(), 0, sizeof(HWND));
                 else
-                    ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * ci->nActiveChildren);
-
-                ci->child[ci->nActiveChildren - 1] = (HWND)lParam;
+                    ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * (ci->nActiveChildren + 1));
+
+                if (ci->child != NULL)
+                {
+                    ci->child[ci->nActiveChildren] = (HWND)lParam;
+                    ci->nTotalCreated++;
+                    ci->nActiveChildren++;
+                }
             }
             break;
 
@@ -1343,6 +1356,8 @@
             {
                 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
                 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+                if (text == NULL)
+                    return 0;
                 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
                 MDI_UpdateFrameText( hwnd, hwndMDIClient, text );
                 HeapFree( GetProcessHeap(), 0, text );



More information about the Ros-diffs mailing list