From 54b75f3de3b3ab7b1cd3807b18bb9bb5f2f8cc8d Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Tue, 11 Dec 2012 13:37:41 +0100 Subject: [PATCH] netapi32: Avoid sizeof on structs with a varlength array. --- dlls/netapi32/nbt.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/dlls/netapi32/nbt.c b/dlls/netapi32/nbt.c index 3cd8a61133b..1bbcaf048db 100644 --- a/dlls/netapi32/nbt.c +++ b/dlls/netapi32/nbt.c @@ -407,9 +407,8 @@ static BOOL NetBTFindNameAnswerCallback(void *pVoid, WORD answerCount, { if (queryData->cacheEntry == NULL) { - queryData->cacheEntry = HeapAlloc( - GetProcessHeap(), 0, sizeof(NBNameCacheEntry) + - (answerCount - 1) * sizeof(DWORD)); + queryData->cacheEntry = HeapAlloc(GetProcessHeap(), 0, + FIELD_OFFSET(NBNameCacheEntry, addresses[answerCount])); if (queryData->cacheEntry) queryData->cacheEntry->numAddresses = 0; else @@ -541,8 +540,8 @@ static UCHAR NetBTinetResolve(const UCHAR name[NCBNAMSZ], if (addr != INADDR_NONE) { - *cacheEntry = HeapAlloc(GetProcessHeap(), - 0, sizeof(NBNameCacheEntry)); + *cacheEntry = HeapAlloc(GetProcessHeap(), 0, + FIELD_OFFSET(NBNameCacheEntry, addresses[1])); if (*cacheEntry) { memcpy((*cacheEntry)->name, name, NCBNAMSZ); @@ -566,9 +565,8 @@ static UCHAR NetBTinetResolve(const UCHAR name[NCBNAMSZ], ; if (host->h_addr_list && host->h_addr_list[0]) { - *cacheEntry = HeapAlloc( - GetProcessHeap(), 0, sizeof(NBNameCacheEntry) + - (i - 1) * sizeof(DWORD)); + *cacheEntry = HeapAlloc(GetProcessHeap(), 0, + FIELD_OFFSET(NBNameCacheEntry, addresses[i])); if (*cacheEntry) { memcpy((*cacheEntry)->name, name, NCBNAMSZ);