Michael Stefaniuc : iphlpapi: Simplify size calculation of structs with var length array.
Alexandre Julliard
julliard at winehq.org
Mon Dec 10 14:00:38 CST 2012
Module: wine
Branch: master
Commit: 61a029355ec2865c3f83accfa9f1cfb5e5641173
URL: http://source.winehq.org/git/wine.git/?a=commit;h=61a029355ec2865c3f83accfa9f1cfb5e5641173
Author: Michael Stefaniuc <mstefani at redhat.de>
Date: Mon Dec 10 10:22:25 2012 +0100
iphlpapi: Simplify size calculation of structs with var length array.
---
dlls/iphlpapi/ifenum.c | 10 ++--------
dlls/iphlpapi/iphlpapi_main.c | 4 +---
2 files changed, 3 insertions(+), 11 deletions(-)
diff --git a/dlls/iphlpapi/ifenum.c b/dlls/iphlpapi/ifenum.c
index aff88cd..d8eebca 100644
--- a/dlls/iphlpapi/ifenum.c
+++ b/dlls/iphlpapi/ifenum.c
@@ -211,13 +211,10 @@ InterfaceIndexTable *getInterfaceIndexTable(void)
if (indexes) {
struct if_nameindex *p;
- DWORD size = sizeof(InterfaceIndexTable);
for (p = indexes, numInterfaces = 0; p && p->if_name; p++)
numInterfaces++;
- if (numInterfaces > 1)
- size += (numInterfaces - 1) * sizeof(DWORD);
- ret = HeapAlloc(GetProcessHeap(), 0, size);
+ ret = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceIndexTable, indexes[numInterfaces]));
if (ret) {
ret->numIndexes = 0;
for (p = indexes; p && p->if_name; p++)
@@ -241,14 +238,11 @@ InterfaceIndexTable *getNonLoopbackInterfaceIndexTable(void)
if (indexes) {
struct if_nameindex *p;
- DWORD size = sizeof(InterfaceIndexTable);
for (p = indexes, numInterfaces = 0; p && p->if_name; p++)
if (!isLoopbackInterface(fd, p->if_name))
numInterfaces++;
- if (numInterfaces > 1)
- size += (numInterfaces - 1) * sizeof(DWORD);
- ret = HeapAlloc(GetProcessHeap(), 0, size);
+ ret = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceIndexTable, indexes[numInterfaces]));
if (ret) {
ret->numIndexes = 0;
for (p = indexes; p && p->if_name; p++)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 16f138c..9cffe06 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -1505,10 +1505,8 @@ DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL
ret = getIPAddrTable(&table, GetProcessHeap(), 0);
if (ret == NO_ERROR)
{
- ULONG size = sizeof(MIB_IPADDRTABLE);
+ ULONG size = FIELD_OFFSET(MIB_IPADDRTABLE, table[table->dwNumEntries]);
- if (table->dwNumEntries > 1)
- size += (table->dwNumEntries - 1) * sizeof(MIB_IPADDRROW);
if (!pIpAddrTable || *pdwSize < size) {
*pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER;
More information about the wine-cvs
mailing list