iphlpapi: Simplify size calculation of structs with var length array.
This commit is contained in:
parent
034b8d5c3c
commit
61a029355e
|
@ -211,13 +211,10 @@ InterfaceIndexTable *getInterfaceIndexTable(void)
|
||||||
|
|
||||||
if (indexes) {
|
if (indexes) {
|
||||||
struct if_nameindex *p;
|
struct if_nameindex *p;
|
||||||
DWORD size = sizeof(InterfaceIndexTable);
|
|
||||||
|
|
||||||
for (p = indexes, numInterfaces = 0; p && p->if_name; p++)
|
for (p = indexes, numInterfaces = 0; p && p->if_name; p++)
|
||||||
numInterfaces++;
|
numInterfaces++;
|
||||||
if (numInterfaces > 1)
|
ret = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceIndexTable, indexes[numInterfaces]));
|
||||||
size += (numInterfaces - 1) * sizeof(DWORD);
|
|
||||||
ret = HeapAlloc(GetProcessHeap(), 0, size);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret->numIndexes = 0;
|
ret->numIndexes = 0;
|
||||||
for (p = indexes; p && p->if_name; p++)
|
for (p = indexes; p && p->if_name; p++)
|
||||||
|
@ -241,14 +238,11 @@ InterfaceIndexTable *getNonLoopbackInterfaceIndexTable(void)
|
||||||
|
|
||||||
if (indexes) {
|
if (indexes) {
|
||||||
struct if_nameindex *p;
|
struct if_nameindex *p;
|
||||||
DWORD size = sizeof(InterfaceIndexTable);
|
|
||||||
|
|
||||||
for (p = indexes, numInterfaces = 0; p && p->if_name; p++)
|
for (p = indexes, numInterfaces = 0; p && p->if_name; p++)
|
||||||
if (!isLoopbackInterface(fd, p->if_name))
|
if (!isLoopbackInterface(fd, p->if_name))
|
||||||
numInterfaces++;
|
numInterfaces++;
|
||||||
if (numInterfaces > 1)
|
ret = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceIndexTable, indexes[numInterfaces]));
|
||||||
size += (numInterfaces - 1) * sizeof(DWORD);
|
|
||||||
ret = HeapAlloc(GetProcessHeap(), 0, size);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret->numIndexes = 0;
|
ret->numIndexes = 0;
|
||||||
for (p = indexes; p && p->if_name; p++)
|
for (p = indexes; p && p->if_name; p++)
|
||||||
|
|
|
@ -1505,10 +1505,8 @@ DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL
|
||||||
ret = getIPAddrTable(&table, GetProcessHeap(), 0);
|
ret = getIPAddrTable(&table, GetProcessHeap(), 0);
|
||||||
if (ret == NO_ERROR)
|
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) {
|
if (!pIpAddrTable || *pdwSize < size) {
|
||||||
*pdwSize = size;
|
*pdwSize = size;
|
||||||
ret = ERROR_INSUFFICIENT_BUFFER;
|
ret = ERROR_INSUFFICIENT_BUFFER;
|
||||||
|
|
Loading…
Reference in New Issue