mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-22 01:56:00 -04:00
Change the isc_buffer_reserve() to take just buffer pointer
The isc_buffer_reserve() would be passed a reference to the buffer pointer, which was unnecessary as the pointer would never be changed in the current implementation. Remove the extra dereference.
This commit is contained in:
parent
9fd83ea971
commit
aea251f3bc
13 changed files with 50 additions and 59 deletions
|
|
@ -7971,8 +7971,8 @@ data_to_cfg(dns_view_t *view, MDB_val *key, MDB_val *data, isc_buffer_t **text,
|
|||
INSIST(zone_config != NULL && zone_config_len > 0);
|
||||
|
||||
/* zone zonename { config; }; */
|
||||
result = isc_buffer_reserve(text, 6 + zone_name_len + 2 +
|
||||
zone_config_len + 2);
|
||||
result = isc_buffer_reserve(*text, 6 + zone_name_len + 2 +
|
||||
zone_config_len + 2);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
@ -12474,7 +12474,7 @@ named_server_testgen(isc_lex_t *lex, isc_buffer_t **text) {
|
|||
count = strtoul(ptr, NULL, 10);
|
||||
}
|
||||
|
||||
CHECK(isc_buffer_reserve(text, count));
|
||||
CHECK(isc_buffer_reserve(*text, count));
|
||||
for (i = 0; i < count; i++) {
|
||||
CHECK(putuint8(text, chars[i % (sizeof(chars) - 1)]));
|
||||
}
|
||||
|
|
@ -15422,7 +15422,7 @@ static isc_result_t
|
|||
putmem(isc_buffer_t **b, const char *str, size_t len) {
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_buffer_reserve(b, (unsigned int)len);
|
||||
result = isc_buffer_reserve(*b, (unsigned int)len);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
|
@ -15440,7 +15440,7 @@ static isc_result_t
|
|||
putuint8(isc_buffer_t **b, uint8_t val) {
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_buffer_reserve(b, 1);
|
||||
result = isc_buffer_reserve(*b, 1);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ main(int argc, char *argv[]) {
|
|||
|
||||
if (rawdata) {
|
||||
while (fread(&c, 1, 1, f) != 0) {
|
||||
result = isc_buffer_reserve(&input, 1);
|
||||
result = isc_buffer_reserve(input, 1);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
isc_buffer_putuint8(input, (uint8_t)c);
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ main(int argc, char *argv[]) {
|
|||
c = fromhex(*rp++);
|
||||
c *= 16;
|
||||
c += fromhex(*rp++);
|
||||
result = isc_buffer_reserve(&input, 1);
|
||||
result = isc_buffer_reserve(input, 1);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
isc_buffer_putuint8(input, (uint8_t)c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ print_packet(dns_dtdata_t *dt, const dns_master_style_t *style) {
|
|||
}
|
||||
|
||||
for (;;) {
|
||||
isc_buffer_reserve(&b, textlen);
|
||||
isc_buffer_reserve(b, textlen);
|
||||
if (b == NULL) {
|
||||
fatal("out of memory");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2713,7 +2713,7 @@ static isc_result_t
|
|||
putstr(isc_buffer_t **b, const char *str) {
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_buffer_reserve(b, strlen(str));
|
||||
result = isc_buffer_reserve(*b, strlen(str));
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1568,7 +1568,7 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp,
|
|||
if (apl_ent.negative) {
|
||||
isc_buffer_putuint8(aclb, '!');
|
||||
}
|
||||
isc_buffer_reserve(&aclb, INET6_ADDRSTRLEN);
|
||||
isc_buffer_reserve(aclb, INET6_ADDRSTRLEN);
|
||||
result = isc_netaddr_totext(&addr, aclb);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
if ((apl_ent.family == 1 && apl_ent.prefix < 32) ||
|
||||
|
|
@ -1872,7 +1872,7 @@ dns_catz_generate_masterfilename(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
|
|||
rlen += strlen(entry->opts.zonedir) + 1;
|
||||
}
|
||||
|
||||
result = isc_buffer_reserve(buffer, (unsigned int)rlen);
|
||||
result = isc_buffer_reserve(*buffer, (unsigned int)rlen);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
@ -1981,7 +1981,7 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
|
|||
}
|
||||
isc_netaddr_fromsockaddr(&netaddr,
|
||||
&entry->opts.masters.addrs[i]);
|
||||
isc_buffer_reserve(&buffer, INET6_ADDRSTRLEN);
|
||||
isc_buffer_reserve(buffer, INET6_ADDRSTRLEN);
|
||||
result = isc_netaddr_totext(&netaddr, buffer);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
|
|
|
|||
|
|
@ -884,7 +884,7 @@ static isc_result_t
|
|||
putstr(isc_buffer_t **b, const char *str) {
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_buffer_reserve(b, strlen(str));
|
||||
result = isc_buffer_reserve(*b, strlen(str));
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
|
@ -1357,7 +1357,7 @@ dns_dt_datatotext(dns_dtdata_t *d, isc_buffer_t **dest) {
|
|||
CHECK(putstr(dest, d->typebuf));
|
||||
}
|
||||
|
||||
CHECK(isc_buffer_reserve(dest, 1));
|
||||
CHECK(isc_buffer_reserve(*dest, 1));
|
||||
isc_buffer_putuint8(*dest, 0);
|
||||
|
||||
cleanup:
|
||||
|
|
|
|||
|
|
@ -618,7 +618,7 @@ static isc_result_t
|
|||
putstr(isc_buffer_t **b, const char *str) {
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_buffer_reserve(b, strlen(str));
|
||||
result = isc_buffer_reserve(*b, strlen(str));
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -478,7 +478,7 @@ static isc_result_t
|
|||
putstr(isc_buffer_t **b, const char *str) {
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_buffer_reserve(b, strlen(str));
|
||||
result = isc_buffer_reserve(*b, strlen(str));
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11415,7 +11415,7 @@ dns_resolver_dumpquota(dns_resolver_t *res, isc_buffer_t **buf) {
|
|||
" spilled %" PRIuFAST32 ")",
|
||||
nb, count, allowed, dropped);
|
||||
|
||||
result = isc_buffer_reserve(buf, strlen(text));
|
||||
result = isc_buffer_reserve(*buf, strlen(text));
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ isc_buffer_putdecint(isc_buffer_t *b, int64_t v) {
|
|||
l = snprintf(buf, 21, "%" PRId64, v);
|
||||
RUNTIME_CHECK(l <= 21);
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, l);
|
||||
result = isc_buffer_reserve(b, l);
|
||||
REQUIRE(result == ISC_R_SUCCESS);
|
||||
}
|
||||
REQUIRE(isc_buffer_availablelength(b) >= l);
|
||||
|
|
@ -220,7 +220,7 @@ isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r) {
|
|||
REQUIRE(r != NULL);
|
||||
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, r->length);
|
||||
result = isc_buffer_reserve(b, r->length);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
|
@ -256,23 +256,22 @@ isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
|
|||
}
|
||||
|
||||
isc_result_t
|
||||
isc_buffer_reserve(isc_buffer_t **dynbuffer, unsigned int size) {
|
||||
isc_buffer_reserve(isc_buffer_t *dynbuffer, unsigned int size) {
|
||||
size_t len;
|
||||
|
||||
REQUIRE(dynbuffer != NULL);
|
||||
REQUIRE(ISC_BUFFER_VALID(*dynbuffer));
|
||||
REQUIRE(ISC_BUFFER_VALID(dynbuffer));
|
||||
|
||||
len = (*dynbuffer)->length;
|
||||
if ((len - (*dynbuffer)->used) >= size) {
|
||||
len = dynbuffer->length;
|
||||
if ((len - dynbuffer->used) >= size) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
if ((*dynbuffer)->mctx == NULL) {
|
||||
if (dynbuffer->mctx == NULL) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
||||
/* Round to nearest buffer size increment */
|
||||
len = size + (*dynbuffer)->used;
|
||||
len = size + dynbuffer->used;
|
||||
len = (len + ISC_BUFFER_INCR - 1 - ((len - 1) % ISC_BUFFER_INCR));
|
||||
|
||||
/* Cap at UINT_MAX */
|
||||
|
|
@ -280,14 +279,13 @@ isc_buffer_reserve(isc_buffer_t **dynbuffer, unsigned int size) {
|
|||
len = UINT_MAX;
|
||||
}
|
||||
|
||||
if ((len - (*dynbuffer)->used) < size) {
|
||||
if ((len - dynbuffer->used) < size) {
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
|
||||
(*dynbuffer)->base = isc_mem_reget((*dynbuffer)->mctx,
|
||||
(*dynbuffer)->base,
|
||||
(*dynbuffer)->length, len);
|
||||
(*dynbuffer)->length = (unsigned int)len;
|
||||
dynbuffer->base = isc_mem_reget(dynbuffer->mctx, dynbuffer->base,
|
||||
dynbuffer->length, len);
|
||||
dynbuffer->length = (unsigned int)len;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
|
@ -328,7 +326,7 @@ isc_buffer_printf(isc_buffer_t *b, const char *format, ...) {
|
|||
}
|
||||
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, n + 1);
|
||||
result = isc_buffer_reserve(b, n + 1);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,24 +206,17 @@ isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
|
|||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_buffer_reserve(isc_buffer_t **dynbuffer, unsigned int size);
|
||||
isc_buffer_reserve(isc_buffer_t *dynbuffer, unsigned int size);
|
||||
/*!<
|
||||
* \brief Make "size" bytes of space available in the buffer. The buffer
|
||||
* pointer may move when you call this function.
|
||||
*
|
||||
* Requires:
|
||||
*\li "dynbuffer" is not NULL.
|
||||
*
|
||||
*\li "*dynbuffer" is a valid dynamic buffer.
|
||||
*\li "dynbuffer" is a valid dynamic buffer.
|
||||
*
|
||||
* Returns:
|
||||
*\li ISC_R_SUCCESS - success
|
||||
*\li ISC_R_NOMEMORY - no memory available
|
||||
*
|
||||
* Ensures:
|
||||
*\li "*dynbuffer" will be valid on return and will contain all the
|
||||
* original data. However, the buffer pointer may be moved during
|
||||
* reallocation.
|
||||
*/
|
||||
|
||||
void
|
||||
|
|
@ -809,7 +802,7 @@ isc_buffer_putuint8(isc_buffer_t *b, uint8_t val) {
|
|||
|
||||
if (b->autore) {
|
||||
isc_buffer_t *tmp = b;
|
||||
ISC_REQUIRE(isc_buffer_reserve(&tmp, 1) == ISC_R_SUCCESS);
|
||||
ISC_REQUIRE(isc_buffer_reserve(tmp, 1) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ISC_REQUIRE(isc_buffer_availablelength(b) >= 1U);
|
||||
|
|
@ -840,7 +833,7 @@ isc_buffer_putuint16(isc_buffer_t *b, uint16_t val) {
|
|||
|
||||
if (b->autore) {
|
||||
isc_buffer_t *tmp = b;
|
||||
ISC_REQUIRE(isc_buffer_reserve(&tmp, 2) == ISC_R_SUCCESS);
|
||||
ISC_REQUIRE(isc_buffer_reserve(tmp, 2) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ISC_REQUIRE(isc_buffer_availablelength(b) >= 2U);
|
||||
|
|
@ -872,7 +865,7 @@ isc_buffer_putuint24(isc_buffer_t *b, uint32_t val) {
|
|||
|
||||
if (b->autore) {
|
||||
isc_buffer_t *tmp = b;
|
||||
ISC_REQUIRE(isc_buffer_reserve(&tmp, 3) == ISC_R_SUCCESS);
|
||||
ISC_REQUIRE(isc_buffer_reserve(tmp, 3) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ISC_REQUIRE(isc_buffer_availablelength(b) >= 3U);
|
||||
|
|
@ -905,7 +898,7 @@ isc_buffer_putuint32(isc_buffer_t *b, uint32_t val) {
|
|||
|
||||
if (b->autore) {
|
||||
isc_buffer_t *tmp = b;
|
||||
ISC_REQUIRE(isc_buffer_reserve(&tmp, 4) == ISC_R_SUCCESS);
|
||||
ISC_REQUIRE(isc_buffer_reserve(tmp, 4) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ISC_REQUIRE(isc_buffer_availablelength(b) >= 4U);
|
||||
|
|
@ -939,7 +932,7 @@ isc_buffer_putuint48(isc_buffer_t *b, uint64_t val) {
|
|||
|
||||
if (b->autore) {
|
||||
isc_buffer_t *tmp = b;
|
||||
ISC_REQUIRE(isc_buffer_reserve(&tmp, 6) == ISC_R_SUCCESS);
|
||||
ISC_REQUIRE(isc_buffer_reserve(tmp, 6) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ISC_REQUIRE(isc_buffer_availablelength(b) >= 6U);
|
||||
|
|
@ -975,7 +968,7 @@ isc_buffer_putmem(isc_buffer_t *b, const unsigned char *base,
|
|||
|
||||
if (b->autore) {
|
||||
isc_buffer_t *tmp = b;
|
||||
ISC_REQUIRE(isc_buffer_reserve(&tmp, length) == ISC_R_SUCCESS);
|
||||
ISC_REQUIRE(isc_buffer_reserve(tmp, length) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ISC_REQUIRE(isc_buffer_availablelength(b) >= (unsigned int)length);
|
||||
|
|
@ -1011,7 +1004,7 @@ isc_buffer_putstr(isc_buffer_t *b, const char *source) {
|
|||
length = (unsigned int)strlen(source);
|
||||
if (b->autore) {
|
||||
isc_buffer_t *tmp = b;
|
||||
ISC_REQUIRE(isc_buffer_reserve(&tmp, length) == ISC_R_SUCCESS);
|
||||
ISC_REQUIRE(isc_buffer_reserve(tmp, length) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ISC_REQUIRE(isc_buffer_availablelength(b) >= length);
|
||||
|
|
|
|||
|
|
@ -113,14 +113,14 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) {
|
|||
if (isccc_sexpr_binaryp(elt)) {
|
||||
vr = isccc_sexpr_tobinary(elt);
|
||||
len = REGION_SIZE(*vr);
|
||||
result = isc_buffer_reserve(buffer, 1 + 4);
|
||||
result = isc_buffer_reserve(*buffer, 1 + 4);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
isc_buffer_putuint8(*buffer, ISCCC_CCMSGTYPE_BINARYDATA);
|
||||
isc_buffer_putuint32(*buffer, len);
|
||||
|
||||
result = isc_buffer_reserve(buffer, len);
|
||||
result = isc_buffer_reserve(*buffer, len);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) {
|
|||
unsigned int used;
|
||||
isc_buffer_t b;
|
||||
|
||||
result = isc_buffer_reserve(buffer, 1 + 4);
|
||||
result = isc_buffer_reserve(*buffer, 1 + 4);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) {
|
|||
unsigned int used;
|
||||
isc_buffer_t b;
|
||||
|
||||
result = isc_buffer_reserve(buffer, 1 + 4);
|
||||
result = isc_buffer_reserve(*buffer, 1 + 4);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ table_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer) {
|
|||
/*
|
||||
* Emit the key name.
|
||||
*/
|
||||
result = isc_buffer_reserve(buffer, 1 + len);
|
||||
result = isc_buffer_reserve(*buffer, 1 + len);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
|
|
@ -313,7 +313,7 @@ isccc_cc_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer, uint32_t algorithm,
|
|||
unsigned int hmac_base, signed_base;
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_buffer_reserve(buffer,
|
||||
result = isc_buffer_reserve(*buffer,
|
||||
4 + ((algorithm == ISCCC_ALG_HMACMD5)
|
||||
? sizeof(auth_hmd5)
|
||||
: sizeof(auth_hsha)));
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ ISC_RUN_TEST_IMPL(isc_buffer_reserve) {
|
|||
* 1024 bytes should already be available, so this call does
|
||||
* nothing.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, 1024);
|
||||
result = isc_buffer_reserve(b, 1024);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
|
|
@ -59,7 +59,7 @@ ISC_RUN_TEST_IMPL(isc_buffer_reserve) {
|
|||
* This call should grow it to 2048 bytes as only 1024 bytes are
|
||||
* available in the buffer.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, 1025);
|
||||
result = isc_buffer_reserve(b, 1025);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
|
|
@ -69,7 +69,7 @@ ISC_RUN_TEST_IMPL(isc_buffer_reserve) {
|
|||
* 2048 bytes should already be available, so this call does
|
||||
* nothing.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, 2000);
|
||||
result = isc_buffer_reserve(b, 2000);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
|
|
@ -79,7 +79,7 @@ ISC_RUN_TEST_IMPL(isc_buffer_reserve) {
|
|||
* This call should grow it to 4096 bytes as only 2048 bytes are
|
||||
* available in the buffer.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, 3000);
|
||||
result = isc_buffer_reserve(b, 3000);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
|
|
@ -91,7 +91,7 @@ ISC_RUN_TEST_IMPL(isc_buffer_reserve) {
|
|||
/*
|
||||
* This call should fail and leave buffer untouched.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, UINT_MAX);
|
||||
result = isc_buffer_reserve(b, UINT_MAX);
|
||||
assert_int_equal(result, ISC_R_NOMEMORY);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
|
|
|
|||
Loading…
Reference in a new issue