localspl: Avoid using sizeof on structs with variable length array.

This commit is contained in:
Michael Stefaniuc 2012-11-02 15:11:26 +01:00 committed by Alexandre Julliard
parent d1f2b8a809
commit e67deeb8a1

View file

@ -513,7 +513,6 @@ cleanup:
static BOOL WINAPI localmon_OpenPortW(LPWSTR pName, PHANDLE phPort) static BOOL WINAPI localmon_OpenPortW(LPWSTR pName, PHANDLE phPort)
{ {
port_t * port; port_t * port;
DWORD len;
DWORD type; DWORD type;
TRACE("%s, %p)\n", debugstr_w(pName), phPort); TRACE("%s, %p)\n", debugstr_w(pName), phPort);
@ -525,12 +524,11 @@ static BOOL WINAPI localmon_OpenPortW(LPWSTR pName, PHANDLE phPort)
type = get_type_from_local_name(pName); type = get_type_from_local_name(pName);
if (!type) return FALSE; if (!type) return FALSE;
len = (lstrlenW(pName) + 1) * sizeof(WCHAR); port = heap_alloc(FIELD_OFFSET(port_t, nameW[lstrlenW(pName) + 1]));
port = heap_alloc(sizeof(port_t) + len);
if (!port) return FALSE; if (!port) return FALSE;
port->type = type; port->type = type;
memcpy(port->nameW, pName, len); lstrcpyW(port->nameW, pName);
*phPort = port; *phPort = port;
EnterCriticalSection(&port_handles_cs); EnterCriticalSection(&port_handles_cs);
@ -734,16 +732,14 @@ static DWORD WINAPI localmon_XcvDataPort(HANDLE hXcv, LPCWSTR pszDataName, PBYTE
*/ */
static BOOL WINAPI localmon_XcvOpenPort(LPCWSTR pName, ACCESS_MASK GrantedAccess, PHANDLE phXcv) static BOOL WINAPI localmon_XcvOpenPort(LPCWSTR pName, ACCESS_MASK GrantedAccess, PHANDLE phXcv)
{ {
DWORD len;
xcv_t * xcv; xcv_t * xcv;
TRACE("%s, 0x%x, %p)\n", debugstr_w(pName), GrantedAccess, phXcv); TRACE("%s, 0x%x, %p)\n", debugstr_w(pName), GrantedAccess, phXcv);
/* No checks for any field is done in Windows */ /* No checks for any field is done in Windows */
len = (lstrlenW(pName) + 1) * sizeof(WCHAR); xcv = heap_alloc(FIELD_OFFSET(xcv_t, nameW[lstrlenW(pName) + 1]));
xcv = heap_alloc( sizeof(xcv_t) + len);
if (xcv) { if (xcv) {
xcv->GrantedAccess = GrantedAccess; xcv->GrantedAccess = GrantedAccess;
memcpy(xcv->nameW, pName, len); lstrcpyW(xcv->nameW, pName);
*phXcv = xcv; *phXcv = xcv;
EnterCriticalSection(&xcv_handles_cs); EnterCriticalSection(&xcv_handles_cs);
list_add_tail(&xcv_handles, &xcv->entry); list_add_tail(&xcv_handles, &xcv->entry);