2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 06:55:30 +00:00

cleanup set_offsets; make dns_name_issubdomain more efficient

This commit is contained in:
Bob Halley
1999-01-09 01:17:09 +00:00
parent 011021d301
commit b5b97de45a

View File

@@ -404,7 +404,6 @@ dns_name_compare(dns_name_t *name1, dns_name_t *name2) {
isc_boolean_t isc_boolean_t
dns_name_issubdomain(dns_name_t *name1, dns_name_t *name2) { dns_name_issubdomain(dns_name_t *name1, dns_name_t *name2) {
isc_boolean_t a1, a2;
unsigned int l1, l2, count1, count2; unsigned int l1, l2, count1, count2;
unsigned int b1, b2, n; unsigned int b1, b2, n;
unsigned char c1, c2; unsigned char c1, c2;
@@ -426,15 +425,16 @@ dns_name_issubdomain(dns_name_t *name1, dns_name_t *name2) {
REQUIRE(VALID_NAME(name2)); REQUIRE(VALID_NAME(name2));
REQUIRE(name2->labels > 0); REQUIRE(name2->labels > 0);
/* We're not going for maximal speed yet... */
a1 = dns_name_isabsolute(name1);
a2 = dns_name_isabsolute(name2);
REQUIRE((a1 && a2) || (!a1 && !a2));
SETUP_OFFSETS(name1, offsets1, odata1); SETUP_OFFSETS(name1, offsets1, odata1);
SETUP_OFFSETS(name2, offsets2, odata2); SETUP_OFFSETS(name2, offsets2, odata2);
/*
* Either name1 is absolute and name2 is absolute, or neither is.
*/
REQUIRE(((name1->ndata[offsets1[name1->labels - 1]] == 0 ? 1 : 0) ^
(name2->ndata[offsets2[name2->labels - 1]] == 0 ? 1 : 0))
== 0);
l1 = name1->labels; l1 = name1->labels;
l2 = name2->labels; l2 = name2->labels;
if (l1 < l2) if (l1 < l2)
@@ -1244,15 +1244,14 @@ set_offsets(dns_name_t *name, unsigned char *offsets, isc_boolean_t set_labels,
if (count > 63) { if (count > 63) {
INSIST(count == DNS_LABELTYPE_BITSTRING); INSIST(count == DNS_LABELTYPE_BITSTRING);
INSIST(nrem != 0); INSIST(nrem != 0);
count = *ndata++; n = *ndata++;
nrem--; nrem--;
offset++; offset++;
if (count == 0) if (n == 0)
count = 256; n = 256;
n = count / 8; count = n / 8;
if (count % 8 != 0) if (n % 8 != 0)
n++; count++;
count = n;
} }
INSIST(nrem >= count); INSIST(nrem >= count);
nrem -= count; nrem -= count;
@@ -1264,6 +1263,7 @@ set_offsets(dns_name_t *name, unsigned char *offsets, isc_boolean_t set_labels,
if (set_length) if (set_length)
name->length = offset; name->length = offset;
INSIST(nlabels == name->labels); INSIST(nlabels == name->labels);
INSIST(offset == name->length);
} }
static void static void