Commit 6d58a948 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

user32: Use standard C functions for memory allocation in combo.c.

The big win here is getting rid of the reimplementation of strdup.
parent a17f55f2
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define OEMRESOURCE #define OEMRESOURCE
#include <stdlib.h>
#include "user_private.h" #include "user_private.h"
#include "controls.h" #include "controls.h"
#include "wine/debug.h" #include "wine/debug.h"
...@@ -112,7 +113,7 @@ static LRESULT COMBO_NCCreate(HWND hwnd, LONG style) ...@@ -112,7 +113,7 @@ static LRESULT COMBO_NCCreate(HWND hwnd, LONG style)
{ {
LPHEADCOMBO lphc; LPHEADCOMBO lphc;
if (COMBO_Init() && (lphc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEADCOMBO))) ) if( COMBO_Init() && (lphc = calloc( 1, sizeof(HEADCOMBO) )) )
{ {
lphc->self = hwnd; lphc->self = hwnd;
SetWindowLongPtrW( hwnd, 0, (LONG_PTR)lphc ); SetWindowLongPtrW( hwnd, 0, (LONG_PTR)lphc );
...@@ -154,7 +155,7 @@ static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc ) ...@@ -154,7 +155,7 @@ static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc )
NtUserDestroyWindow( lphc->hWndLBox ); NtUserDestroyWindow( lphc->hWndLBox );
SetWindowLongPtrW( lphc->self, 0, 0 ); SetWindowLongPtrW( lphc->self, 0, 0 );
HeapFree( GetProcessHeap(), 0, lphc ); free( lphc );
} }
return 0; return 0;
} }
...@@ -641,7 +642,7 @@ static void CBPaintText( ...@@ -641,7 +642,7 @@ static void CBPaintText(
size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0); size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0);
if (size == LB_ERR) if (size == LB_ERR)
FIXME("LB_ERR probably not handled yet\n"); FIXME("LB_ERR probably not handled yet\n");
if( (pText = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))) ) if( (pText = malloc((size + 1) * sizeof(WCHAR))) )
{ {
/* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */ /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
size=SendMessageW(lphc->hWndLBox, LB_GETTEXT, id, (LPARAM)pText); size=SendMessageW(lphc->hWndLBox, LB_GETTEXT, id, (LPARAM)pText);
...@@ -736,7 +737,7 @@ static void CBPaintText( ...@@ -736,7 +737,7 @@ static void CBPaintText(
if (!hdc_paint) if (!hdc_paint)
NtUserReleaseDC( lphc->self, hdc ); NtUserReleaseDC( lphc->self, hdc );
} }
HeapFree( GetProcessHeap(), 0, pText ); free(pText);
} }
/*********************************************************************** /***********************************************************************
...@@ -830,7 +831,7 @@ static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect ) ...@@ -830,7 +831,7 @@ static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 ); length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 );
if( length > 0 ) if( length > 0 )
pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR)); pText = malloc((length + 1) * sizeof(WCHAR));
TRACE("\t edit text length %i\n", length ); TRACE("\t edit text length %i\n", length );
...@@ -838,7 +839,7 @@ static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect ) ...@@ -838,7 +839,7 @@ static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
{ {
GetWindowTextW( lphc->hWndEdit, pText, length + 1); GetWindowTextW( lphc->hWndEdit, pText, length + 1);
idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING, -1, (LPARAM)pText); idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING, -1, (LPARAM)pText);
HeapFree( GetProcessHeap(), 0, pText ); free(pText);
} }
SendMessageW(lphc->hWndLBox, LB_SETCURSEL, bSelect ? idx : -1, 0); SendMessageW(lphc->hWndLBox, LB_SETCURSEL, bSelect ? idx : -1, 0);
...@@ -867,7 +868,7 @@ static void CBUpdateEdit( LPHEADCOMBO lphc , INT index ) ...@@ -867,7 +868,7 @@ static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, index, 0); length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, index, 0);
if( length != LB_ERR) if( length != LB_ERR)
{ {
if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) ) if( (pText = malloc((length + 1) * sizeof(WCHAR))) )
{ {
SendMessageW(lphc->hWndLBox, LB_GETTEXT, index, (LPARAM)pText); SendMessageW(lphc->hWndLBox, LB_GETTEXT, index, (LPARAM)pText);
} }
...@@ -884,7 +885,7 @@ static void CBUpdateEdit( LPHEADCOMBO lphc , INT index ) ...@@ -884,7 +885,7 @@ static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
if( lphc->wState & CBF_FOCUSED ) if( lphc->wState & CBF_FOCUSED )
SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, -1); SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, -1);
HeapFree( GetProcessHeap(), 0, pText ); free(pText);
} }
/*********************************************************************** /***********************************************************************
...@@ -1295,7 +1296,7 @@ static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf ) ...@@ -1295,7 +1296,7 @@ static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf )
/* 'length' is without the terminating character */ /* 'length' is without the terminating character */
if (length >= count) if (length >= count)
{ {
LPWSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR)); WCHAR *lpBuffer = malloc((length + 1) * sizeof(WCHAR));
if (!lpBuffer) goto error; if (!lpBuffer) goto error;
length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer); length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
...@@ -1305,7 +1306,7 @@ static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf ) ...@@ -1305,7 +1306,7 @@ static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf )
lstrcpynW( buf, lpBuffer, count ); lstrcpynW( buf, lpBuffer, count );
length = count; length = count;
} }
HeapFree( GetProcessHeap(), 0, lpBuffer ); free(lpBuffer);
} }
else length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf); else length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
...@@ -1345,7 +1346,7 @@ static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf ) ...@@ -1345,7 +1346,7 @@ static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf )
/* 'length' is without the terminating character */ /* 'length' is without the terminating character */
if (length >= count) if (length >= count)
{ {
LPSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) ); char *lpBuffer = malloc(length + 1);
if (!lpBuffer) goto error; if (!lpBuffer) goto error;
length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer); length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
...@@ -1355,7 +1356,7 @@ static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf ) ...@@ -1355,7 +1356,7 @@ static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf )
lstrcpynA( buf, lpBuffer, count ); lstrcpynA( buf, lpBuffer, count );
length = count; length = count;
} }
HeapFree( GetProcessHeap(), 0, lpBuffer ); free(lpBuffer);
} }
else length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf); else length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
...@@ -1678,19 +1679,6 @@ static LRESULT COMBO_GetComboBoxInfo(const HEADCOMBO *lphc, COMBOBOXINFO *pcbi) ...@@ -1678,19 +1679,6 @@ static LRESULT COMBO_GetComboBoxInfo(const HEADCOMBO *lphc, COMBOBOXINFO *pcbi)
return TRUE; return TRUE;
} }
static char *strdupA(LPCSTR str)
{
char *ret;
DWORD len;
if(!str) return NULL;
len = strlen(str);
ret = HeapAlloc(GetProcessHeap(), 0, len + 1);
memcpy(ret, str, len + 1);
return ret;
}
/*********************************************************************** /***********************************************************************
* ComboWndProc_common * ComboWndProc_common
*/ */
...@@ -1927,18 +1915,18 @@ LRESULT ComboWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lPar ...@@ -1927,18 +1915,18 @@ LRESULT ComboWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lPar
LRESULT ret; LRESULT ret;
if( lphc->dwStyle & CBS_LOWERCASE ) if( lphc->dwStyle & CBS_LOWERCASE )
{ {
string = strdupA((LPSTR)lParam); string = strdup((char *)lParam);
CharLowerA(string); CharLowerA(string);
} }
else if( lphc->dwStyle & CBS_UPPERCASE ) else if( lphc->dwStyle & CBS_UPPERCASE )
{ {
string = strdupA((LPSTR)lParam); string = strdup((char *)lParam);
CharUpperA(string); CharUpperA(string);
} }
ret = SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, string ? (LPARAM)string : lParam); ret = SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, string ? (LPARAM)string : lParam);
HeapFree(GetProcessHeap(), 0, string); free(string);
return ret; return ret;
} }
case CB_INSERTSTRING: case CB_INSERTSTRING:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment