Commit a96e118d authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

snmpapi: Test and correct SnmpUtilOidNCmp when Oid lengths don't match.

parent d88ee55e
......@@ -343,17 +343,21 @@ VOID WINAPI SnmpUtilOidFree(AsnObjectIdentifier *oid)
*/
INT WINAPI SnmpUtilOidNCmp(AsnObjectIdentifier *oid1, AsnObjectIdentifier *oid2, UINT count)
{
unsigned int i;
unsigned int i, len;
TRACE("(%p, %p, %d)\n", oid1, oid2, count);
if (!oid1 || !oid2) return 0;
for (i = 0; i < count; i++)
len = min(count, oid1->idLength);
len = min(len, oid2->idLength);
for (i = 0; i < len; i++)
{
if (oid1->ids[i] > oid2->ids[i]) return 1;
if (oid1->ids[i] < oid2->ids[i]) return -1;
}
if (oid1->idLength < oid2->idLength) return -1;
if (oid1->idLength > oid2->idLength) return 1;
return 0;
}
......
......@@ -321,6 +321,15 @@ static void test_SnmpUtilOidNCmp(void)
ret = SnmpUtilOidNCmp(&oid2, &oid1, 4);
ok(ret == 1, "SnmpUtilOidNCmp failed: %d\n", ret);
oid1.idLength = 3;
memcpy(oid1.ids, oid2.ids, sizeof(UINT) * 4);
ret = SnmpUtilOidNCmp(&oid1, &oid1, 4);
ok(!ret, "SnmpUtilOidNCmp failed: %d\n", ret);
ret = SnmpUtilOidNCmp(&oid2, &oid1, 4);
ok(ret == 1, "SnmpUtilOidNCmp failed: %d\n", ret);
ret = SnmpUtilOidNCmp(&oid1, &oid2, 4);
ok(ret == -1, "SnmpUtilOidNCmp failed: %d\n", ret);
}
static void test_SnmpUtilOidCmp(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment