The difference between two ULONGs may not fit in an int, causing comparison errors.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- v2: Introduce DWORD_cmp() to simplify the comparisons. v3: Spelling fix.
compareIpAddrRow() and oidToIpForwardRow() should also do byte-swapping which will be done in the next patch. --- dlls/inetmib1/main.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/dlls/inetmib1/main.c b/dlls/inetmib1/main.c index 90da277375e..e66dbe0a811 100644 --- a/dlls/inetmib1/main.c +++ b/dlls/inetmib1/main.c @@ -770,11 +770,15 @@ static void oidToIpAddrRow(AsnObjectIdentifier *oid, void *dst) row->dwAddr = oidToIpAddr(oid); }
-static int __cdecl compareIpAddrRow(const void *a, const void *b) +static int __cdecl DWORD_cmp(DWORD a, DWORD b) { - const MIB_IPADDRROW *key = a, *value = b; + return a < b ? -1 : a > b ? 1 : 0; /* a subtraction would overflow */ +}
- return key->dwAddr - value->dwAddr; +static int __cdecl compareIpAddrRow(const void *a, const void *b) +{ + const MIB_IPADDRROW *rowA = a, *rowB = b; + return DWORD_cmp(rowA->dwAddr, rowB->dwAddr); }
static BOOL mib2IpAddrQuery(BYTE bPduType, SnmpVarBind *pVarBind, @@ -865,9 +869,8 @@ static void oidToIpForwardRow(AsnObjectIdentifier *oid, void *dst)
static int __cdecl compareIpForwardRow(const void *a, const void *b) { - const MIB_IPFORWARDROW *key = a, *value = b; - - return key->dwForwardDest - value->dwForwardDest; + const MIB_IPFORWARDROW *rowA = a, *rowB = b; + return DWORD_cmp(rowA->dwForwardDest, rowB->dwForwardDest); }
static BOOL mib2IpRouteQuery(BYTE bPduType, SnmpVarBind *pVarBind, @@ -1223,13 +1226,9 @@ static void oidToUdpRow(AsnObjectIdentifier *oid, void *dst)
static int __cdecl compareUdpRow(const void *a, const void *b) { - const MIB_UDPROW *key = a, *value = b; - int ret; - - ret = ntohl(key->dwLocalAddr) - ntohl(value->dwLocalAddr); - if (ret == 0) - ret = ntohs(key->dwLocalPort) - ntohs(value->dwLocalPort); - return ret; + const MIB_UDPROW *rowA = a, *rowB = b; + return DWORD_cmp(ntohl(rowA->dwLocalAddr), ntohl(rowB->dwLocalAddr)) || + ntohs(rowA->dwLocalPort) - ntohs(rowB->dwLocalPort); }
static BOOL mib2UdpEntryQuery(BYTE bPduType, SnmpVarBind *pVarBind,