Compare commits

...
4 Commits
Author SHA1 Message Date
Evan Hunt f882f90c95 fixup! Improve qp-trie leaf return values 2023-04-06 17:14:35 -07:00
Tony Finch 6512137c52 Improve qp-trie leaf return values
Make the `pval_r` and `ival_r` out arguments optional.

Add `pval_r` and `ival_r` out arguments to `dns_qp_deletekey()`
and `dns_qp_deletename()`, to return the deleted leaf.
2023-04-06 17:22:37 +01:00
Tony Finch aeff328f8b Apply the OUTARG() semantic patch
spatch --sp-file cocci/outarg.spatch --use-gitgrep --dir "." --include-headers --in-place
2023-04-06 17:22:37 +01:00
Tony Finch 36943c7c1c An OUTARG() macro for optional return values
The OUTARG() macro avoids a fair amount of tedious boilerplate.
I have included a Coccinelle semantic patch to use OUTARG()
where appropriate. The patch needs a #include in `openssl_shim.c`
in order to work.
2023-04-06 17:22:37 +01:00
38 changed files with 150 additions and 260 deletions
+1 -3
View File
@@ -4553,9 +4553,7 @@ getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp) {
result = isc_getaddresses(host, 0, sockaddrs, DIG_MAX_ADDRESSES,
&count);
isc_loopmgr_nonblocking(loopmgr);
if (resultp != NULL) {
*resultp = result;
}
OUTARG(resultp, result);
if (result != ISC_R_SUCCESS) {
if (resultp == NULL) {
fatal("couldn't get address for '%s': %s", host,
+2 -6
View File
@@ -291,15 +291,11 @@ strtotime(const char *str, int64_t now, int64_t base, bool *setp) {
struct tm tm;
if (isnone(str)) {
if (setp != NULL) {
*setp = false;
}
OUTARG(setp, false);
return ((isc_stdtime_t)0);
}
if (setp != NULL) {
*setp = true;
}
OUTARG(setp, true);
if ((str[0] == '0' || str[0] == '-') && str[1] == '\0') {
return ((isc_stdtime_t)0);
+2 -6
View File
@@ -984,11 +984,7 @@ named_config_getkeyalgorithm2(const char *str, const dns_name_t **name,
UNREACHABLE();
}
}
if (typep != NULL) {
*typep = algorithms[i].type;
}
if (digestbits != NULL) {
*digestbits = bits;
}
OUTARG(typep, algorithms[i].type);
OUTARG(digestbits, bits);
return (ISC_R_SUCCESS);
}
+4 -12
View File
@@ -270,9 +270,7 @@ pack_soa_record(unsigned char *rdatap, size_t rbufsz, size_t *rdlenp,
rdatap += 4;
used += (4 * 5);
if (rdlenp != NULL) {
*rdlenp = used;
}
OUTARG(rdlenp, used);
return (true);
}
@@ -1889,9 +1887,7 @@ domain_pton2(const char *src, u_char *dst, size_t dstsiz, size_t *dstlen,
tptr = tmps;
if (dstlen != NULL) {
*dstlen = 0;
}
OUTARG(dstlen, 0);
while (tptr && *tptr) {
tok = strsep(&tptr, ".");
@@ -2117,9 +2113,7 @@ trpz_rsp_rr(librpz_emsg_t *emsg, uint16_t *typep, uint16_t *classp,
*ttlp = 3600;
}
if (typep != NULL) {
*typep = this_rr->type;
}
OUTARG(typep, this_rr->type);
if (rrp != NULL) {
uint8_t *copy_src = NULL, *nrdata = NULL;
@@ -2205,9 +2199,7 @@ trpz_rsp_rr(librpz_emsg_t *emsg, uint16_t *typep, uint16_t *classp,
trsp->rstack[0].result.next_rr = this_rr->rrn;
last_result->rridx++;
} else {
if (typep != NULL) {
*typep = ns_t_invalid;
}
OUTARG(typep, ns_t_invalid);
if (rrp != NULL) {
*rrp = NULL;
+1 -3
View File
@@ -1113,9 +1113,7 @@ sanity_check_data_file(const char *fname, char **errp) {
FILE *f = NULL;
int result = -1;
if (errp != NULL) {
*errp = NULL;
}
OUTARG(errp, NULL);
f = fopen(fname, "r");
if (f == NULL) {
+14
View File
@@ -0,0 +1,14 @@
@@
type T;
identifier fun;
identifier arg;
expression val;
@@
fun(..., T *arg, ...) {
...
- if (arg != NULL) {
- *arg = val;
- }
+ OUTARG(arg, val);
...
}
+2 -1
View File
@@ -179,7 +179,8 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
UNREACHABLE();
}
} else {
result = dns_qp_deletekey(qp, item[i].key, item[i].len);
result = dns_qp_deletekey(qp, item[i].key, item[i].len,
NULL, NULL);
TRACE("count %zu del %s %zu >%s<", count,
isc_result_toid(result), i, item[i].ascii);
if (result == ISC_R_SUCCESS) {
+5 -15
View File
@@ -3696,25 +3696,15 @@ dns_adb_getquota(dns_adb_t *adb, uint32_t *quotap, uint32_t *freqp,
double *lowp, double *highp, double *discountp) {
REQUIRE(DNS_ADB_VALID(adb));
if (quotap != NULL) {
*quotap = adb->quota;
}
OUTARG(quotap, adb->quota);
if (freqp != NULL) {
*freqp = adb->atr_freq;
}
OUTARG(freqp, adb->atr_freq);
if (lowp != NULL) {
*lowp = adb->atr_low;
}
OUTARG(lowp, adb->atr_low);
if (highp != NULL) {
*highp = adb->atr_high;
}
OUTARG(highp, adb->atr_high);
if (discountp != NULL) {
*discountp = adb->atr_discount;
}
OUTARG(discountp, adb->atr_discount);
}
static bool
+19 -13
View File
@@ -445,12 +445,11 @@ dns_qp_getkey(dns_qpreadable_t qpr, const dns_qpkey_t search_key,
/*%<
* Find a leaf in a qp-trie that matches the given search key
*
* The leaf values are assigned to `*pval_r` and `*ival_r`
* The leaf values are assigned to whichever of `*pval_r` and `*ival_r`
* are not null, unless the return value is ISC_R_NOTFOUND.
*
* Requires:
* \li `qpr` is a pointer to a readable qp-trie
* \li `pval_r != NULL`
* \li `ival_r != NULL`
* \li `search_keylen < sizeof(dns_qpkey_t)`
*
* Returns:
@@ -464,13 +463,12 @@ dns_qp_getname(dns_qpreadable_t qpr, const dns_name_t *name, void **pval_r,
/*%<
* Find a leaf in a qp-trie that matches the given DNS name
*
* The leaf values are assigned to `*pval_r` and `*ival_r`
* The leaf values are assigned to whichever of `*pval_r` and `*ival_r`
* are not null, unless the return value is ISC_R_NOTFOUND.
*
* Requires:
* \li `qpr` is a pointer to a readable qp-trie
* \li `name` is a pointer to a valid `dns_name_t`
* \li `pval_r != NULL`
* \li `ival_r != NULL`
*
* Returns:
* \li ISC_R_NOTFOUND if the trie has no leaf with a matching key
@@ -487,13 +485,12 @@ dns_qp_findname_parent(dns_qpreadable_t qpr, const dns_name_t *name,
* If the DNS_QPFIND_NOEXACT option is set, find a strict parent
* domain not equal to the search name.
*
* The leaf values are assigned to `*pval_r` and `*ival_r`
* The leaf values are assigned to whichever of `*pval_r` and `*ival_r`
* are not null, unless the return value is ISC_R_NOTFOUND.
*
* Requires:
* \li `qpr` is a pointer to a readable qp-trie
* \li `name` is a pointer to a valid `dns_name_t`
* \li `pval_r != NULL`
* \li `ival_r != NULL`
*
* Returns:
* \li ISC_R_SUCCESS if an exact match was found
@@ -517,10 +514,14 @@ dns_qp_insert(dns_qp_t *qp, void *pval, uint32_t ival);
*/
isc_result_t
dns_qp_deletekey(dns_qp_t *qp, const dns_qpkey_t key, size_t keylen);
dns_qp_deletekey(dns_qp_t *qp, const dns_qpkey_t key, size_t keylen,
void **pval_r, uint32_t *ival_r);
/*%<
* Delete a leaf from a qp-trie that matches the given key
*
* The leaf values are assigned to whichever of `*pval_r` and `*ival_r`
* are not null, unless the return value is ISC_R_NOTFOUND.
*
* Requires:
* \li `qp` is a pointer to a valid qp-trie
* \li `keylen < sizeof(dns_qpkey_t)`
@@ -531,10 +532,14 @@ dns_qp_deletekey(dns_qp_t *qp, const dns_qpkey_t key, size_t keylen);
*/
isc_result_t
dns_qp_deletename(dns_qp_t *qp, const dns_name_t *name);
dns_qp_deletename(dns_qp_t *qp, const dns_name_t *name, void **pval_r,
uint32_t *ival_r);
/*%<
* Delete a leaf from a qp-trie that matches the given DNS name
*
* The leaf values are assigned to whichever of `*pval_r` and `*ival_r`
* are not null, unless the return value is ISC_R_NOTFOUND.
*
* Requires:
* \li `qp` is a pointer to a valid qp-trie
* \li `name` is a pointer to a valid qp-trie
@@ -564,6 +569,9 @@ dns_qpiter_next(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r);
/*%<
* Get the next leaf object of a trie in lexicographic order of its keys.
*
* The leaf values are assigned to whichever of `*pval_r` and `*ival_r`
* are not null, unless the return value is ISC_R_NOMORE.
*
* NOTE: see the safety note under `dns_qpiter_init()`.
*
* For example,
@@ -578,8 +586,6 @@ dns_qpiter_next(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r);
*
* Requires:
* \li `qpi` is a pointer to a valid qp iterator
* \li `pval_r != NULL`
* \li `ival_r != NULL`
*
* Returns:
* \li ISC_R_SUCCESS if a leaf was found and pval_r and ival_r were set
+3 -9
View File
@@ -2633,12 +2633,8 @@ dns_message_peekheader(isc_buffer_t *source, dns_messageid_t *idp,
flags = isc_buffer_getuint16(&buffer);
flags &= DNS_MESSAGE_FLAG_MASK;
if (flagsp != NULL) {
*flagsp = flags;
}
if (idp != NULL) {
*idp = id;
}
OUTARG(flagsp, flags);
OUTARG(idp, id);
return (ISC_R_SUCCESS);
}
@@ -2786,9 +2782,7 @@ dns_message_gettsig(dns_message_t *msg, const dns_name_t **owner) {
REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(owner == NULL || *owner == NULL);
if (owner != NULL) {
*owner = msg->tsigname;
}
OUTARG(owner, msg->tsigname);
return (msg->tsig);
}
+1 -3
View File
@@ -271,9 +271,7 @@ dns_nsec3_hashname(dns_fixedname_t *result,
return (DNS_R_BADALG);
}
if (hash_length != NULL) {
*hash_length = len;
}
OUTARG(hash_length, len);
/* convert the hash to base32hex non-padded */
region.base = rethash;
+13 -33
View File
@@ -13,6 +13,8 @@
#include "openssl_shim.h"
#include <isc/util.h>
#if !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L
/* From OpenSSL 1.1.0 */
int
@@ -96,39 +98,23 @@ RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) {
void
RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
const BIGNUM **d) {
if (n != NULL) {
*n = r->n;
}
if (e != NULL) {
*e = r->e;
}
if (d != NULL) {
*d = r->d;
}
OUTARG(n, r->n);
OUTARG(e, r->e);
OUTARG(d, r->d);
}
void
RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) {
if (p != NULL) {
*p = r->p;
}
if (q != NULL) {
*q = r->q;
}
OUTARG(p, r->p);
OUTARG(q, r->q);
}
void
RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1,
const BIGNUM **iqmp) {
if (dmp1 != NULL) {
*dmp1 = r->dmp1;
}
if (dmq1 != NULL) {
*dmq1 = r->dmq1;
}
if (iqmp != NULL) {
*iqmp = r->iqmp;
}
OUTARG(dmp1, r->dmp1);
OUTARG(dmq1, r->dmq1);
OUTARG(iqmp, r->iqmp);
}
int
@@ -141,12 +127,8 @@ RSA_test_flags(const RSA *r, int flags) {
/* From OpenSSL 1.1 */
void
ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) {
if (pr != NULL) {
*pr = sig->r;
}
if (ps != NULL) {
*ps = sig->s;
}
OUTARG(pr, sig->r);
OUTARG(ps, sig->s);
}
int
@@ -170,9 +152,7 @@ static const char err_empty_string = '\0';
unsigned long
ERR_get_error_all(const char **file, int *line, const char **func,
const char **data, int *flags) {
if (func != NULL) {
*func = &err_empty_string;
}
OUTARG(func, &err_empty_string);
return (ERR_get_error_line_data(file, line, data, flags));
}
#endif /* if !HAVE_ERR_GET_ERROR_ALL */
+14 -17
View File
@@ -1627,7 +1627,7 @@ growbranch:
isc_result_t
dns_qp_deletekey(dns_qp_t *qp, const dns_qpkey_t search_key,
size_t search_keylen) {
size_t search_keylen, void **pval_r, uint32_t *ival_r) {
REQUIRE(QP_VALID(qp));
REQUIRE(search_keylen < sizeof(dns_qpkey_t));
@@ -1657,6 +1657,8 @@ dns_qp_deletekey(dns_qp_t *qp, const dns_qpkey_t search_key,
return (ISC_R_NOTFOUND);
}
OUTARG(pval_r, leaf_pval(n));
OUTARG(ival_r, leaf_ival(n));
detach_leaf(qp, n);
qp->leaf_count--;
@@ -1699,10 +1701,11 @@ dns_qp_deletekey(dns_qp_t *qp, const dns_qpkey_t search_key,
}
isc_result_t
dns_qp_deletename(dns_qp_t *qp, const dns_name_t *name) {
dns_qp_deletename(dns_qp_t *qp, const dns_name_t *name, void **pval_r,
uint32_t *ival_r) {
dns_qpkey_t key;
size_t keylen = dns_qpkey_fromname(key, name);
return (dns_qp_deletekey(qp, key, keylen));
return (dns_qp_deletekey(qp, key, keylen, pval_r, ival_r));
}
/***********************************************************************
@@ -1730,8 +1733,6 @@ isc_result_t
dns_qpiter_next(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) {
REQUIRE(QPITER_VALID(qpi));
REQUIRE(QP_VALID(qpi->qp));
REQUIRE(pval_r != NULL);
REQUIRE(ival_r != NULL);
dns_qpreader_t *qp = qpi->qp;
@@ -1745,8 +1746,8 @@ dns_qpiter_next(dns_qpiter_t *qpi, void **pval_r, uint32_t *ival_r) {
for (;;) {
qp_node_t *n = ref_ptr(qp, qpi->stack[qpi->sp].ref);
if (node_tag(n) == LEAF_TAG) {
*pval_r = leaf_pval(n);
*ival_r = leaf_ival(n);
OUTARG(pval_r, leaf_pval(n));
OUTARG(ival_r, leaf_ival(n));
break;
}
qpi->sp++;
@@ -1786,8 +1787,6 @@ dns_qp_getkey(dns_qpreadable_t qpr, const dns_qpkey_t search_key,
qp_node_t *n = NULL;
REQUIRE(QP_VALID(qp));
REQUIRE(pval_r != NULL);
REQUIRE(ival_r != NULL);
REQUIRE(search_keylen < sizeof(dns_qpkey_t));
n = get_root(qp);
@@ -1811,8 +1810,8 @@ dns_qp_getkey(dns_qpreadable_t qpr, const dns_qpkey_t search_key,
return (ISC_R_NOTFOUND);
}
*pval_r = leaf_pval(n);
*ival_r = leaf_ival(n);
OUTARG(pval_r, leaf_pval(n));
OUTARG(ival_r, leaf_ival(n));
return (ISC_R_SUCCESS);
}
@@ -1841,8 +1840,6 @@ dns_qp_findname_parent(dns_qpreadable_t qpr, const dns_name_t *name,
} label[DNS_NAME_MAXLABELS];
REQUIRE(QP_VALID(qp));
REQUIRE(pval_r != NULL);
REQUIRE(ival_r != NULL);
searchlen = dns_qpkey_fromname(search, name);
if ((options & DNS_QPFIND_NOEXACT) != 0) {
@@ -1902,8 +1899,8 @@ dns_qp_findname_parent(dns_qpreadable_t qpr, const dns_name_t *name,
offset = qpkey_compare(search, searchlen, found, foundlen);
if (offset == QPKEY_EQUAL || offset == foundlen) {
*pval_r = leaf_pval(n);
*ival_r = leaf_ival(n);
OUTARG(pval_r, leaf_pval(n));
OUTARG(ival_r, leaf_ival(n));
if (offset == QPKEY_EQUAL) {
return (result);
} else {
@@ -1913,8 +1910,8 @@ dns_qp_findname_parent(dns_qpreadable_t qpr, const dns_name_t *name,
while (labels-- > 0) {
if (offset > label[labels].off) {
n = ref_ptr(qp, label[labels].ref);
*pval_r = leaf_pval(n);
*ival_r = leaf_ival(n);
OUTARG(pval_r, leaf_pval(n));
OUTARG(ival_r, leaf_ival(n));
return (DNS_R_PARTIALMATCH);
}
}
+2 -6
View File
@@ -7892,13 +7892,9 @@ getsize(dns_db_t *db, dns_dbversion_t *version, uint64_t *records,
}
RWLOCK(&rbtversion->rwlock, isc_rwlocktype_read);
if (records != NULL) {
*records = rbtversion->records;
}
OUTARG(records, rbtversion->records);
if (xfrsize != NULL) {
*xfrsize = rbtversion->xfrsize;
}
OUTARG(xfrsize, rbtversion->xfrsize);
RWUNLOCK(&rbtversion->rwlock, isc_rwlocktype_read);
RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_read);
+1 -3
View File
@@ -247,9 +247,7 @@ finish:
isc_textregion_consume(region, 1);
}
RETERR(uint16_tobuffer(ul, target));
if (value != NULL) {
*value = ul;
}
OUTARG(value, ul);
return (ISC_R_SUCCESS);
}
+5 -15
View File
@@ -6841,9 +6841,7 @@ is_answertarget_allowed(fetchctx_t *fctx, dns_name_t *qname, dns_name_t *rname,
result = dns_name_concatenate(&prefix, &dname.dname, tname,
NULL);
if (result == DNS_R_NAMETOOLONG) {
if (chainingp != NULL) {
*chainingp = true;
}
OUTARG(chainingp, true);
return (true);
}
RUNTIME_CHECK(result == ISC_R_SUCCESS);
@@ -6852,9 +6850,7 @@ is_answertarget_allowed(fetchctx_t *fctx, dns_name_t *qname, dns_name_t *rname,
UNREACHABLE();
}
if (chainingp != NULL) {
*chainingp = true;
}
OUTARG(chainingp, true);
if (view->denyanswernames == NULL) {
return (true);
@@ -10959,15 +10955,9 @@ dns_resolver_getclientsperquery(dns_resolver_t *resolver, uint32_t *cur,
REQUIRE(VALID_RESOLVER(resolver));
LOCK(&resolver->lock);
if (cur != NULL) {
*cur = resolver->spillat;
}
if (min != NULL) {
*min = resolver->spillatmin;
}
if (max != NULL) {
*max = resolver->spillatmax;
}
OUTARG(cur, resolver->spillat);
OUTARG(min, resolver->spillatmin);
OUTARG(max, resolver->spillatmax);
UNLOCK(&resolver->lock);
}
+2 -6
View File
@@ -210,11 +210,7 @@ dns_rriterator_current(dns_rriterator_t *it, dns_name_t **name, uint32_t *ttl,
dns_rdata_reset(&it->rdata);
dns_rdataset_current(&it->rdataset, &it->rdata);
if (rdataset != NULL) {
*rdataset = &it->rdataset;
}
OUTARG(rdataset, &it->rdataset);
if (rdata != NULL) {
*rdata = &it->rdata;
}
OUTARG(rdata, &it->rdata);
}
+1 -3
View File
@@ -336,9 +336,7 @@ dns_tsigkey_createfromkey(const dns_name_t *name, const dns_name_t *algorithm,
namestr);
}
if (key != NULL) {
*key = tkey;
}
OUTARG(key, tkey);
if (tkey->restored) {
tsig_log(tkey, ISC_LOG_DEBUG(3), "restored from file");
+4 -12
View File
@@ -851,9 +851,7 @@ is_active(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, bool *flag,
if (result == ISC_R_SUCCESS || result == DNS_R_EMPTYNAME) {
*flag = true;
*cut = false;
if (unsecure != NULL) {
*unsecure = false;
}
OUTARG(unsecure, false);
return (ISC_R_SUCCESS);
} else if (result == DNS_R_ZONECUT) {
*flag = true;
@@ -879,9 +877,7 @@ is_active(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, bool *flag,
{
*flag = false;
*cut = false;
if (unsecure != NULL) {
*unsecure = false;
}
OUTARG(unsecure, false);
return (ISC_R_SUCCESS);
} else {
/*
@@ -889,9 +885,7 @@ is_active(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, bool *flag,
*/
*flag = false;
*cut = false;
if (unsecure != NULL) {
*unsecure = false;
}
OUTARG(unsecure, false);
return (result);
}
}
@@ -2267,9 +2261,7 @@ dns_update_soaserial(uint32_t serial, dns_updatemethod_t method,
UNREACHABLE();
}
if (used != NULL) {
*used = method;
}
OUTARG(used, method);
return (new_serial);
}
+2 -6
View File
@@ -5455,12 +5455,8 @@ zone_count_ns_rr(dns_zone_t *zone, dns_db_t *db, dns_dbnode_t *node,
dns_rdataset_disassociate(&rdataset);
success:
if (nscount != NULL) {
*nscount = count;
}
if (errors != NULL) {
*errors = ecount;
}
OUTARG(nscount, count);
OUTARG(errors, ecount);
result = ISC_R_SUCCESS;
+6 -10
View File
@@ -157,7 +157,7 @@ dns_zt_unmount(dns_zt_t *zt, dns_zone_t *zone) {
REQUIRE(VALID_ZT(zt));
dns_qpmulti_write(zt->multi, &qp);
result = dns_qp_deletename(qp, dns_zone_getorigin(zone));
result = dns_qp_deletename(qp, dns_zone_getorigin(zone), NULL, NULL);
dns_qp_compact(qp, DNS_QPGC_MAYBE);
dns_qpmulti_commit(zt->multi, &qp);
@@ -170,7 +170,6 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options,
isc_result_t result;
dns_qpread_t qpr;
void *pval = NULL;
uint32_t ival;
dns_ztfind_t exactmask = DNS_ZTFIND_NOEXACT | DNS_ZTFIND_EXACT;
dns_ztfind_t exactopts = options & exactmask;
@@ -183,12 +182,12 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options,
dns_qpmulti_query(zt->multi, &qpr);
}
if (exactopts == DNS_ZTFIND_EXACT) {
result = dns_qp_getname(&qpr, name, &pval, &ival);
result = dns_qp_getname(&qpr, name, &pval, NULL);
} else if (exactopts == DNS_ZTFIND_NOEXACT) {
result = dns_qp_findname_parent(&qpr, name, DNS_QPFIND_NOEXACT,
&pval, &ival);
&pval, NULL);
} else {
result = dns_qp_findname_parent(&qpr, name, 0, &pval, &ival);
result = dns_qp_findname_parent(&qpr, name, 0, &pval, NULL);
}
dns_qpread_destroy(zt->multi, &qpr);
@@ -512,7 +511,6 @@ dns_zt_apply(dns_zt_t *zt, bool stop, isc_result_t *sub,
dns_qpiter_t qpi;
dns_qpread_t qpr;
void *zone = NULL;
uint32_t ival;
REQUIRE(VALID_ZT(zt));
REQUIRE(action != NULL);
@@ -520,7 +518,7 @@ dns_zt_apply(dns_zt_t *zt, bool stop, isc_result_t *sub,
dns_qpmulti_query(zt->multi, &qpr);
dns_qpiter_init(&qpr, &qpi);
while (dns_qpiter_next(&qpi, &zone, &ival) == ISC_R_SUCCESS) {
while (dns_qpiter_next(&qpi, &zone, NULL) == ISC_R_SUCCESS) {
result = action(zone, uap);
if (tresult == ISC_R_SUCCESS) {
tresult = result;
@@ -531,9 +529,7 @@ dns_zt_apply(dns_zt_t *zt, bool stop, isc_result_t *sub,
}
dns_qpread_destroy(zt->multi, &qpr);
if (sub != NULL) {
*sub = tresult;
}
OUTARG(sub, tresult);
return (result);
}
+1 -3
View File
@@ -347,9 +347,7 @@ isc_hashmap_find(const isc_hashmap_t *hashmap, const uint32_t *hashvalp,
}
INSIST(node->key != NULL);
if (valuep != NULL) {
*valuep = node->value;
}
OUTARG(valuep, node->value);
return (ISC_R_SUCCESS);
}
-10
View File
@@ -34,16 +34,6 @@
#define STRUCT_FLEX_SIZE(pointer, member, count) \
(sizeof(*(pointer)) + sizeof(*(pointer)->member) * (count))
/*
* XXXFANF this should probably be in <isc/util.h> too
*/
#define OUTARG(ptr, val) \
({ \
if ((ptr) != NULL) { \
*(ptr) = (val); \
} \
})
#define HISTO_MAGIC ISC_MAGIC('H', 's', 't', 'o')
#define HISTO_VALID(p) ISC_MAGIC_VALID(p, HISTO_MAGIC)
#define HISTOMULTI_MAGIC ISC_MAGIC('H', 'g', 'M', 't')
+1 -3
View File
@@ -372,9 +372,7 @@ isc_ht_find(const isc_ht_t *ht, const unsigned char *key,
return (ISC_R_NOTFOUND);
}
if (valuep != NULL) {
*valuep = node->value;
}
OUTARG(valuep, node->value);
return (ISC_R_SUCCESS);
}
+4 -12
View File
@@ -844,9 +844,7 @@ isc_buffer_peekuint8(const isc_buffer_t *restrict b, uint8_t *valp) {
ISC_BUFFER_PEEK_CHECK(b, sizeof(*valp));
uint8_t *cp = isc_buffer_current(b);
if (valp != NULL) {
*valp = (uint8_t)(cp[0]);
}
OUTARG(valp, (uint8_t)(cp[0]));
return (ISC_R_SUCCESS);
}
@@ -887,9 +885,7 @@ isc_buffer_peekuint16(const isc_buffer_t *restrict b, uint16_t *valp) {
uint8_t *cp = isc_buffer_current(b);
if (valp != NULL) {
*valp = ISC_U8TO16_BE(cp);
}
OUTARG(valp, ISC_U8TO16_BE(cp));
return (ISC_R_SUCCESS);
}
@@ -917,9 +913,7 @@ isc_buffer_peekuint32(const isc_buffer_t *restrict b, uint32_t *valp) {
uint8_t *cp = isc_buffer_current(b);
if (valp != NULL) {
*valp = ISC_U8TO32_BE(cp);
}
OUTARG(valp, ISC_U8TO32_BE(cp));
return (ISC_R_SUCCESS);
}
@@ -948,9 +942,7 @@ isc_buffer_peekuint48(const isc_buffer_t *restrict b, uint64_t *valp) {
uint8_t *cp = isc_buffer_current(b);
if (valp != NULL) {
*valp = ISC_U8TO48_BE(cp);
}
OUTARG(valp, ISC_U8TO48_BE(cp));
return (ISC_R_SUCCESS);
}
+10
View File
@@ -96,6 +96,16 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
/*
* Optional return values, or out-arguments
*/
#define OUTARG(ptr, val) \
({ \
if ((ptr) != NULL) { \
*(ptr) = (val); \
} \
})
/*%
* Use this in translation units that would otherwise be empty, to
* suppress compiler warnings.
+1 -3
View File
@@ -286,9 +286,7 @@ isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp) {
atomic_init(&lctx->dynamic, lcfg->dynamic);
*lctxp = lctx;
if (lcfgp != NULL) {
*lcfgp = lcfg;
}
OUTARG(lcfgp, lcfg);
}
void
+4 -12
View File
@@ -386,21 +386,13 @@ isc_nm_gettimeouts(isc_nm_t *mgr, uint32_t *initial, uint32_t *idle,
uint32_t *keepalive, uint32_t *advertised) {
REQUIRE(VALID_NM(mgr));
if (initial != NULL) {
*initial = atomic_load_relaxed(&mgr->init);
}
OUTARG(initial, atomic_load_relaxed(&mgr->init));
if (idle != NULL) {
*idle = atomic_load_relaxed(&mgr->idle);
}
OUTARG(idle, atomic_load_relaxed(&mgr->idle));
if (keepalive != NULL) {
*keepalive = atomic_load_relaxed(&mgr->keepalive);
}
OUTARG(keepalive, atomic_load_relaxed(&mgr->keepalive));
if (advertised != NULL) {
*advertised = atomic_load_relaxed(&mgr->advertised);
}
OUTARG(advertised, atomic_load_relaxed(&mgr->advertised));
}
bool
+2 -6
View File
@@ -85,9 +85,7 @@ isc_stdio_read(void *ptr, size_t size, size_t nmemb, FILE *f, size_t *nret) {
result = isc__errno2result(errno);
}
}
if (nret != NULL) {
*nret = r;
}
OUTARG(nret, r);
return (result);
}
@@ -102,9 +100,7 @@ isc_stdio_write(const void *ptr, size_t size, size_t nmemb, FILE *f,
if (r != nmemb) {
result = isc__errno2result(errno);
}
if (nret != NULL) {
*nret = r;
}
OUTARG(nret, r);
return (result);
}
+1 -3
View File
@@ -161,9 +161,7 @@ isc_symtab_lookup(isc_symtab_t *symtab, const char *key, unsigned int type,
return (ISC_R_NOTFOUND);
}
if (value != NULL) {
*value = elt->value;
}
OUTARG(value, elt->value);
return (ISC_R_SUCCESS);
}
+1 -3
View File
@@ -132,9 +132,7 @@ isc_thread_join(isc_thread_t thread, isc_threadresult_t *result) {
PTHREADS_RUNTIME_CHECK(pthread_join, ret);
struct thread_wrap *wrap = wrap_v;
if (result != NULL) {
*result = wrap->result;
}
OUTARG(result, wrap->result);
free(wrap->jemalloc_enforce_init);
free(wrap);
}
+1 -3
View File
@@ -198,9 +198,7 @@ isccc_symtab_lookup(isccc_symtab_t *symtab, const char *key, unsigned int type,
return (ISC_R_NOTFOUND);
}
if (value != NULL) {
*value = elt->value;
}
OUTARG(value, elt->value);
return (ISC_R_SUCCESS);
}
+1 -3
View File
@@ -1144,9 +1144,7 @@ check_port(const cfg_obj_t *options, isc_log_t *logctx, const char *type,
return (ISC_R_RANGE);
}
if (portp != NULL) {
*portp = (in_port_t)cfg_obj_asuint32(portobj);
}
OUTARG(portp, (in_port_t)cfg_obj_asuint32(portobj));
return (ISC_R_SUCCESS);
}
+2 -6
View File
@@ -1089,9 +1089,7 @@ query_validatezonedb(ns_client_t *client, const dns_name_t *name,
approved:
/* Transfer ownership, if necessary. */
if (versionp != NULL) {
*versionp = dbversion->version;
}
OUTARG(versionp, dbversion->version);
return (ISC_R_SUCCESS);
}
@@ -1492,9 +1490,7 @@ query_isduplicate(ns_client_t *client, dns_name_t *name, dns_rdatatype_t type,
mname = NULL;
}
if (mnamep != NULL) {
*mnamep = mname;
}
OUTARG(mnamep, mname);
CTRACE(ISC_LOG_DEBUG(3), "query_isduplicate: false: done");
return (false);
+1 -2
View File
@@ -168,8 +168,7 @@ sqz_qp(void *qp) {
static isc_result_t
get_qp(void *qp, size_t count, void **pval) {
uint32_t ival = 0;
return (dns_qp_getname(qp, &item[count].fixed.name, pval, &ival));
return (dns_qp_getname(qp, &item[count].fixed.name, pval, NULL));
}
/*
+2 -1
View File
@@ -310,7 +310,8 @@ mutate_transactions(uv_idle_t *idle) {
uint32_t i = isc_random_uniform(args->max_item);
if (item[i].present) {
isc_result_t result = dns_qp_deletekey(
qp, item[i].key, item[i].len);
qp, item[i].key, item[i].len, NULL,
NULL);
INSIST(result == ISC_R_SUCCESS);
item[i].present = false;
args->present++;
+7 -4
View File
@@ -188,7 +188,11 @@ ISC_RUN_TEST_IMPL(qpiter) {
dns_qpkey_t key;
size_t len = qpiter_makekey(key, item, pval, ival);
if (dns_qp_insert(qp, pval, ival) == ISC_R_EXISTS) {
dns_qp_deletekey(qp, key, len);
void *pvald = NULL;
uint32_t ivald = 0;
dns_qp_deletekey(qp, key, len, &pvald, &ivald);
assert_ptr_equal(pval, pvald);
assert_int_equal(ival, ivald);
item[ival] = 0;
}
@@ -256,7 +260,6 @@ check_partialmatch(dns_qp_t *qp, struct check_partialmatch check[]) {
dns_fixedname_t fixed;
dns_name_t *name = dns_fixedname_name(&fixed);
void *pval = NULL;
uint32_t ival;
#if 0
fprintf(stderr, "%s %u %s %s\n", check[i].query,
@@ -265,7 +268,7 @@ check_partialmatch(dns_qp_t *qp, struct check_partialmatch check[]) {
#endif
dns_test_namefromstring(check[i].query, &fixed);
result = dns_qp_findname_parent(qp, name, check[i].options,
&pval, &ival);
&pval, NULL);
assert_int_equal(result, check[i].result);
if (check[i].found == NULL) {
assert_null(pval);
@@ -340,7 +343,7 @@ ISC_RUN_TEST_IMPL(partialmatch) {
/* what if entries in the trie are relative to the zone apex? */
dns_qpkey_t rootkey = { SHIFT_NOBYTE };
result = dns_qp_deletekey(qp, rootkey, 1);
result = dns_qp_deletekey(qp, rootkey, 1, NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
INSIST(insert[i][0] == '\0');
insert_str(qp, insert[i++]);
+7 -4
View File
@@ -159,7 +159,6 @@ random_byte(void) {
static void
setup_items(void) {
void *pval = NULL;
uint32_t ival = ~0U;
dns_qp_t *qp = NULL;
dns_qp_create(mctx, &test_methods, NULL, &qp);
for (size_t i = 0; i < ARRAY_SIZE(item); i++) {
@@ -172,7 +171,7 @@ setup_items(void) {
memmove(item[i].ascii, item[i].key, len);
qp_test_keytoascii(item[i].ascii, len);
} while (dns_qp_getkey(qp, item[i].key, item[i].len, &pval,
&ival) == ISC_R_SUCCESS);
NULL) == ISC_R_SUCCESS);
assert_int_equal(dns_qp_insert(qp, &item[i], i), ISC_R_SUCCESS);
}
dns_qp_destroy(&qp);
@@ -283,9 +282,13 @@ one_transaction(dns_qpmulti_t *qpm) {
if (item[i].in_rw) {
/* TRACE("delete %zu %.*s", i,
item[i].len, item[i].ascii); */
result = dns_qp_deletekey(qpw, item[i].key,
item[i].len);
void *pvald = NULL;
uint32_t ivald = 0;
result = dns_qp_deletekey(qpw, item[i].key, item[i].len,
&pvald, &ivald);
ASSERT(result == ISC_R_SUCCESS);
ASSERT(pvald == &item[i]);
ASSERT(ivald == i);
item[i].in_rw = false;
} else {
/* TRACE("insert %zu %.*s", i,