]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Split dns_name_copy() into dns_name_copy() and dns_name_copynf()
authorOndřej Surý <ondrej@sury.org>
Tue, 10 Sep 2019 12:36:41 +0000 (14:36 +0200)
committerMark Andrews <marka@isc.org>
Tue, 1 Oct 2019 00:43:26 +0000 (10:43 +1000)
The dns_name_copy() function followed two different semanitcs that was driven
whether the last argument was or wasn't NULL.  This commit splits the function
in two where now third argument to dns_name_copy() can't be NULL and
dns_name_copynf() doesn't have third argument.

lib/dns/include/dns/name.h
lib/dns/name.c
lib/dns/win32/libdns.def.in

index ae840785fbf47b0d78808a5080719acdaf954a6d..f25ecd5d9ba169d72d58f05d405fa3ab5709b19d 100644 (file)
@@ -1240,16 +1240,19 @@ dns_name_settotextfilter(dns_name_totextfilter_t proc);
 
 isc_result_t
 dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target);
+void
+dns_name_copynf(const dns_name_t *source, dns_name_t *dest);
 /*%<
- * Makes 'dest' refer to a copy of the name in 'source'.  The data are
- * either copied to 'target' or the dedicated buffer in 'dest'.
+ * Makes 'dest' refer to a copy of the name in 'source'.  The data are either
+ * copied to 'target' or in case of dns_name_copyfixed the dedicated buffer in
+ * 'dest'.
  *
  * Requires:
  * \li 'source' is a valid name.
  *
  * \li 'dest' is an initialized name with a dedicated buffer.
  *
- * \li 'target' is NULL or an initialized buffer.
+ * \li 'target' is an initialized buffer.
  *
  * \li Either dest has a dedicated buffer or target != NULL.
  *
index 12dafa8e2aac23250b710fc7139a118e49309810..2c021aad1f848340470489feb5554c2ff629d122 100644 (file)
@@ -2443,50 +2443,46 @@ dns_name_fromstring2(dns_name_t *target, const char *src,
        return (result);
 }
 
+static
 isc_result_t
-dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
+name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
        unsigned char *ndata;
 
        /*
         * Make dest a copy of source.
         */
 
-       REQUIRE(VALID_NAME(source));
-       REQUIRE(VALID_NAME(dest));
-       REQUIRE(target != NULL || dest->buffer != NULL);
-
-       if (target == NULL) {
-               target = dest->buffer;
-               isc_buffer_clear(dest->buffer);
-       }
-
        REQUIRE(BINDABLE(dest));
 
        /*
         * Set up.
         */
-       if (target->length - target->used < source->length)
+       if (target->length - target->used < source->length) {
                return (ISC_R_NOSPACE);
+       }
 
        ndata = (unsigned char *)target->base + target->used;
        dest->ndata = target->base;
 
-       if (source->length != 0)
+       if (source->length != 0) {
                memmove(ndata, source->ndata, source->length);
+       }
 
        dest->ndata = ndata;
        dest->labels = source->labels;
        dest->length = source->length;
-       if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
+       if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
                dest->attributes = DNS_NAMEATTR_ABSOLUTE;
-       else
+       } else {
                dest->attributes = 0;
+       }
 
        if (dest->labels > 0 && dest->offsets != NULL) {
-               if (source->offsets != NULL)
+               if (source->offsets != NULL) {
                        memmove(dest->offsets, source->offsets, source->labels);
-               else
+               } else {
                        set_offsets(dest, dest->offsets, NULL);
+               }
        }
 
        isc_buffer_add(target, dest->length);
@@ -2494,6 +2490,27 @@ dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target)
        return (ISC_R_SUCCESS);
 }
 
+isc_result_t
+dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target)
+{
+       REQUIRE(VALID_NAME(source));
+       REQUIRE(VALID_NAME(dest));
+       REQUIRE(target != NULL);
+
+       return (name_copy(source, dest, target));
+}
+
+void
+dns_name_copynf(const dns_name_t *source, dns_name_t *dest)
+{
+       REQUIRE(VALID_NAME(source));
+       REQUIRE(VALID_NAME(dest));
+       REQUIRE(dest->buffer != NULL);
+
+       isc_buffer_clear(dest->buffer);
+       RUNTIME_CHECK(name_copy(source, dest, dest->buffer) == ISC_R_SUCCESS);
+}
+
 void
 dns_name_destroy(void) {
        RUNTIME_CHECK(isc_once_do(&once, thread_key_mutex_init)
index 99cbe11a6d7392a74158df5717dc89221bad8d2a..44092edcef9d13fcdd282a4ab985ca63738838f4 100644 (file)
@@ -538,6 +538,7 @@ dns_name_clone
 dns_name_compare
 dns_name_concatenate
 dns_name_copy
+dns_name_copynf
 dns_name_countlabels
 dns_name_destroy
 dns_name_digest