remove dns_name_copy() implementation

Remove dns_name_copy() and refactor the underlying code since
it will only be called by dns_name_copynf() now, and can't fail.
This commit is contained in:
Evan Hunt 2021-05-21 17:17:23 -07:00
parent b1fe1b8ae3
commit ea7b28f101
3 changed files with 14 additions and 59 deletions

View file

@ -1240,33 +1240,12 @@ dns_name_settotextfilter(dns_name_totextfilter_t *proc);
* Includes space for the terminating NULL.
*/
isc_result_t
dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target);
/*%<
* Copies the name in 'source' into 'dest'. The name data is copied to
* the 'target' buffer, which is then set as the buffer for 'dest'.
*
* Requires:
* \li 'source' is a valid name.
*
* \li 'dest' is an initialized name.
*
* \li 'target' is an initialized buffer.
*
* Ensures:
*
*\li On success, the used space in target is updated.
*
* Returns:
*\li #ISC_R_SUCCESS
*\li #ISC_R_NOSPACE
*/
void
dns_name_copynf(const dns_name_t *source, dns_name_t *dest);
/*%<
* Copies the name in 'source' into 'dest'. The name data is copied to
* the dedicated buffer for 'dest'.
* the dedicated buffer for 'dest'. (If copying to a name that doesn't
* have a dedicated buffer, use dns_name_setbuffer() first.)
*
* Requires:
* \li 'source' is a valid name.

View file

@ -2462,24 +2462,23 @@ dns_name_fromstring2(dns_name_t *target, const char *src,
return (result);
}
static isc_result_t
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) {
isc_buffer_t *target = NULL;
unsigned char *ndata = NULL;
/*
* Make dest a copy of source.
*/
REQUIRE(VALID_NAME(source));
REQUIRE(VALID_NAME(dest));
REQUIRE(BINDABLE(dest));
/*
* Set up.
*/
if (target->length - target->used < source->length) {
return (ISC_R_NOSPACE);
}
target = dest->buffer;
ndata = (unsigned char *)target->base + target->used;
REQUIRE(target != NULL);
REQUIRE(target->length >= source->length);
isc_buffer_clear(target);
ndata = (unsigned char *)target->base;
dest->ndata = target->base;
if (source->length != 0) {
@ -2504,28 +2503,6 @@ name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
}
isc_buffer_add(target, dest->length);
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);
}
/*

View file

@ -576,7 +576,6 @@ dns_name_caseequal
dns_name_clone
dns_name_compare
dns_name_concatenate
dns_name_copy
dns_name_copynf
dns_name_countlabels
dns_name_digest