From e67deeb8a139f51e63d5f7142c259ca6cd235a40 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Fri, 2 Nov 2012 15:11:26 +0100 Subject: [PATCH] localspl: Avoid using sizeof on structs with variable length array. --- dlls/localspl/localmon.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/dlls/localspl/localmon.c b/dlls/localspl/localmon.c index f4e1739d5cb..8737a060be2 100644 --- a/dlls/localspl/localmon.c +++ b/dlls/localspl/localmon.c @@ -513,7 +513,6 @@ cleanup: static BOOL WINAPI localmon_OpenPortW(LPWSTR pName, PHANDLE phPort) { port_t * port; - DWORD len; DWORD type; 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); if (!type) return FALSE; - len = (lstrlenW(pName) + 1) * sizeof(WCHAR); - port = heap_alloc(sizeof(port_t) + len); + port = heap_alloc(FIELD_OFFSET(port_t, nameW[lstrlenW(pName) + 1])); if (!port) return FALSE; port->type = type; - memcpy(port->nameW, pName, len); + lstrcpyW(port->nameW, pName); *phPort = port; 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) { - DWORD len; xcv_t * xcv; TRACE("%s, 0x%x, %p)\n", debugstr_w(pName), GrantedAccess, phXcv); /* No checks for any field is done in Windows */ - len = (lstrlenW(pName) + 1) * sizeof(WCHAR); - xcv = heap_alloc( sizeof(xcv_t) + len); + xcv = heap_alloc(FIELD_OFFSET(xcv_t, nameW[lstrlenW(pName) + 1])); if (xcv) { xcv->GrantedAccess = GrantedAccess; - memcpy(xcv->nameW, pName, len); + lstrcpyW(xcv->nameW, pName); *phXcv = xcv; EnterCriticalSection(&xcv_handles_cs); list_add_tail(&xcv_handles, &xcv->entry);