CHECK(dns_zone_setjournal(zone, journal));
}
- DE_CONST(classname, region.base);
+ region.base = UNCONST(classname);
region.length = strlen(classname);
CHECK(dns_rdataclass_fromtext(&rdclass, ®ion));
return (ISC_R_FAILURE);
}
- DE_CONST(zclass, r.base);
+ r.base = UNCONST(zclass);
r.length = strlen(zclass);
result = dns_rdataclass_fromtext(&rdclass, &r);
if (result != ISC_R_SUCCESS) {
*classp = defclass;
return (ISC_R_SUCCESS);
}
- DE_CONST(cfg_obj_asstring(classobj), r.base);
+ r.base = UNCONST(cfg_obj_asstring(classobj));
r.length = strlen(r.base);
return (dns_rdataclass_fromtext(classp, &r));
}
nsec3param.hash = unknownalg ? DNS_NSEC3_UNKNOWNALG : dns_hash_sha1;
nsec3param.iterations = iterations;
nsec3param.salt_length = (unsigned char)salt_len;
- DE_CONST(salt, nsec3param.salt);
+ nsec3param.salt = UNCONST(salt);
isc_buffer_init(&b, nsec3parambuf, sizeof(nsec3parambuf));
result = dns_rdata_fromstruct(&rdata, gclass, dns_rdatatype_nsec3param,
char *s;
size_t dlen;
- DE_CONST(sync_records, digest);
+ digest = UNCONST(sync_records);
next_digest:
s = strchr(digest, delim);
if (s == NULL) {
if (str == NULL) {
return (dns_rdataclass_in);
}
- DE_CONST(str, r.base);
+ r.base = UNCONST(str);
r.length = strlen(str);
result = dns_rdataclass_fromtext(&rdclass, &r);
if (result != ISC_R_SUCCESS) {
dns_dsdigest_t alg;
isc_result_t result;
- DE_CONST(str, r.base);
+ r.base = UNCONST(str);
r.length = strlen(str);
result = dns_dsdigest_fromtext(&alg, &r);
if (result != ISC_R_SUCCESS) {
rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
isc_buffer_allocate(mctx, &rdatabuf, rdlen);
- DE_CONST(rdatap, region.base);
+ region.base = UNCONST(rdatap);
region.length = rdlen;
isc_buffer_copyregion(rdatabuf, ®ion);
isc_buffer_usedregion(rdatabuf, ®ion);
*classp = defclass;
return (ISC_R_SUCCESS);
}
- DE_CONST(cfg_obj_asstring(classobj), r.base);
+ r.base = UNCONST(cfg_obj_asstring(classobj));
r.length = strlen(r.base);
result = dns_rdataclass_fromtext(classp, &r);
if (result != ISC_R_SUCCESS) {
*typep = deftype;
return (ISC_R_SUCCESS);
}
- DE_CONST(cfg_obj_asstring(typeobj), r.base);
+ r.base = UNCONST(cfg_obj_asstring(typeobj));
r.length = strlen(r.base);
result = dns_rdatatype_fromtext(typep, &r);
if (result != ISC_R_SUCCESS) {
isc_textregion_t r;
dns_secalg_t alg;
- DE_CONST(cfg_obj_asstring(cfg_listelt_value(element)), r.base);
+ r.base = UNCONST(cfg_obj_asstring(cfg_listelt_value(element)));
r.length = strlen(r.base);
result = dns_secalg_fromtext(&alg, &r);
isc_textregion_t r;
dns_dsdigest_t digest;
- DE_CONST(cfg_obj_asstring(cfg_listelt_value(element)), r.base);
+ r.base = UNCONST(cfg_obj_asstring(cfg_listelt_value(element)));
r.length = strlen(r.base);
/* disable_ds_digests handles numeric values. */
result = named_config_get(maps, "geoip-directory", &obj);
INSIST(result == ISC_R_SUCCESS);
if (cfg_obj_isstring(obj)) {
- char *dir;
- DE_CONST(cfg_obj_asstring(obj), dir);
+ char *dir = UNCONST(cfg_obj_asstring(obj));
named_geoip_load(dir);
}
named_g_aclconfctx->geoip = named_g_geoip;
CHECK(ISC_R_FAILURE);
}
- DE_CONST(&zl->value.list, list);
+ list = UNCONST(&zl->value.list);
CHECK(add_comment(fp, view->name)); /* force a comment */
CHECK(ISC_R_FAILURE);
}
- DE_CONST(&zl->value.list, list);
+ list = UNCONST(&zl->value.list);
myname = dns_fixedname_initname(&myfixed);
continue;
}
- DE_CONST(elt, e);
+ e = UNCONST(elt);
ISC_LIST_UNLINK(*list, e, link);
cfg_obj_destroy(pctx, &e->obj);
isc_mem_put(pctx->mctx, e, sizeof(*e));
if (cfg->nzf_config == NULL) {
cfg_obj_attach(zoneconf, &cfg->nzf_config);
} else {
- cfg_obj_t *z;
- DE_CONST(zoneobj, z);
+ cfg_obj_t *z = UNCONST(zoneobj);
CHECK(cfg_parser_mapadd(cfg->add_parser, cfg->nzf_config, z,
"zone"));
}
#ifndef HAVE_LMDB
/* Store the new zone configuration; also in NZF if applicable */
- DE_CONST(zoneobj, z);
+ z = UNCONST(zoneobj);
CHECK(cfg_parser_mapadd(cfg->add_parser, cfg->nzf_config, z, "zone"));
#endif /* HAVE_LMDB */
*retcode = 200;
*retmsg = "OK";
*mimetype = "application/json";
- DE_CONST(msg, p);
+ p = UNCONST(msg);
isc_buffer_reinit(b, p, msglen);
isc_buffer_add(b, msglen);
*freecb = wrap_jsonfree;
send:
*retcode = 200;
*retmsg = "OK";
- DE_CONST(xslmsg, p);
+ p = UNCONST(xslmsg);
isc_buffer_reinit(b, p, strlen(xslmsg));
isc_buffer_add(b, strlen(xslmsg));
end:
typeobj = cfg_listelt_value(element2);
str = cfg_obj_asstring(typeobj);
- DE_CONST(str, r.base);
+ r.base = UNCONST(str);
bracket = strchr(str, '(' /*)*/);
if (bracket != NULL) {
/* other useful definitions */
#define UNUSED(x) (void)(x)
-#define DE_CONST(konst, var) \
- do { \
- union { \
- const void *k; \
- void *v; \
- } _u; \
- _u.k = konst; \
- var = _u.v; \
- } while (0)
+
+#define UNCONST(ptr) ((void *)(uintptr_t)(ptr))
#if !defined(__has_c_attribute)
#define __has_c_attribute(x) 0
#include <dlz_list.h>
#include <dlz_minimal.h>
-#define DE_CONST(konst, var) \
- do { \
- union { \
- const void *k; \
- void *v; \
- } _u; \
- _u.k = konst; \
- var = _u.v; \
- } while (0)
-
/* fnmatch() return values. */
#define FNM_NOMATCH 1 /* Match failed. */
nrr_t *nrec;
int i = 0;
- DE_CONST(zone, cd->zone);
+ cd->zone = UNCONST(zone);
/* Write info message to log */
cd->log(ISC_LOG_DEBUG(1), "dlz_wildcard allnodes called for zone '%s'",
return (ISC_R_NOTFOUND);
}
- DE_CONST(name, cd->record);
- DE_CONST(p, cd->zone);
+ cd->record = UNCONST(name);
+ cd->zone = UNCONST(p);
if ((p != zone) && (strcmp(name, "@") == 0 || strcmp(name, zone) == 0))
{
return (ISC_R_NOTFOUND);
}
- DE_CONST(p, cd->zone);
+ cd->zone = UNCONST(p);
/* Write info message to log */
cd->log(ISC_LOG_DEBUG(1), "dlz_wildcard_dynamic: authority for '%s'",
if (data == NULL) {
return (ISC_R_FAILURE);
}
- DE_CONST(data, *bufp);
+ *bufp = UNCONST(data);
return (ISC_R_SUCCESS);
case fstrm_res_stop:
return (ISC_R_NOMORE);
strings = 0;
if ((options & DNS_RDATA_UNKNOWNESCAPE) != 0) {
isc_textregion_t r;
- DE_CONST("#", r.base);
+ r.base = UNCONST("#");
r.length = 1;
RETERR(txt_fromtext(&r, target));
strings++;
isc_mem_put(mctx, tkey->creator, sizeof(dns_name_t));
}
if (dns__tsig_algallocated(tkey->algorithm)) {
- dns_name_t *tmpname;
- DE_CONST(tkey->algorithm, tmpname);
+ dns_name_t *tmpname = UNCONST(tkey->algorithm);
if (dns_name_dynamic(tmpname)) {
dns_name_free(tmpname, mctx);
}
key->magic = 0;
dns_name_free(&key->name, key->mctx);
if (dns__tsig_algallocated(key->algorithm)) {
- dns_name_t *name;
- DE_CONST(key->algorithm, name);
+ dns_name_t *name = UNCONST(key->algorithm);
dns_name_free(name, key->mctx);
isc_mem_put(key->mctx, name, sizeof(dns_name_t));
}
dns_view_addtrustedkey(dns_view_t *view, dns_rdatatype_t rdtype,
const dns_name_t *keyname, isc_buffer_t *databuf) {
isc_result_t result;
- dns_name_t *name = NULL;
+ dns_name_t *name = UNCONST(keyname);
char rdatabuf[DST_KEY_MAXSIZE];
unsigned char digest[ISC_MAX_MD_SIZE];
dns_rdata_ds_t ds;
REQUIRE(DNS_VIEW_VALID(view));
REQUIRE(view->rdclass == dns_rdataclass_in);
- DE_CONST(keyname, name);
-
if (rdtype != dns_rdatatype_dnskey && rdtype != dns_rdatatype_ds) {
result = ISC_R_NOTIMPLEMENTED;
goto cleanup;
return (DNS_R_CONTINUE);
} else if (zone->stream != NULL) {
- FILE *stream = NULL;
- DE_CONST(zone->stream, stream);
+ FILE *stream = UNCONST(zone->stream);
result = dns_master_loadstream(
stream, &zone->origin, &zone->origin, zone->rdclass,
options, &load->callbacks, zone->mctx);
n = sscanf(algstr, "%hhu", &alg);
if (n == 0U) {
- DE_CONST(algstr, r.base);
+ r.base = UNCONST(algstr);
r.length = strlen(algstr);
CHECK(dns_secalg_fromtext(&alg, &r));
}
}
if (param->salt_length == 0) {
- DE_CONST("-", param->salt);
+ param->salt = (unsigned char *)"-";
} else if (resalt || param->salt == NULL) {
unsigned char *newsalt;
unsigned char salttext[255 * 2 + 1];
return (true);
}
- DE_CONST(d1 - first->next_length, sr.base);
+ sr.base = UNCONST(d1 - first->next_length);
sr.length = first->next_length;
isc_buffer_init(&b, buf, sizeof(buf));
isc_base32hex_totext(&sr, 1, "", &b);
zoneverify_log_error(vctx, "Break in NSEC3 chain at: %.*s",
(int)isc_buffer_usedlength(&b), buf);
- DE_CONST(d1, sr.base);
+ sr.base = UNCONST(d1);
sr.length = first->next_length;
isc_buffer_init(&b, buf, sizeof(buf));
isc_base32hex_totext(&sr, 1, "", &b);
zoneverify_log_error(vctx, "Expected: %.*s",
(int)isc_buffer_usedlength(&b), buf);
- DE_CONST(d2, sr.base);
+ sr.base = UNCONST(d2);
sr.length = first->next_length;
isc_buffer_init(&b, buf, sizeof(buf));
isc_base32hex_totext(&sr, 1, "", &b);
#define ISC_CLAMP(v, x, y) ((v) < (x) ? (x) : ((v) > (y) ? (y) : (v)))
/*%
- * Use this to remove the const qualifier of a variable to assign it to
- * a non-const variable or pass it as a non-const function argument ...
- * but only when you are sure it won't then be changed!
- * This is necessary to sometimes shut up some compilers
- * (as with gcc -Wcast-qual) when there is just no other good way to avoid the
- * situation.
+ * The UNCONST() macro can be used to omit warnings produced by certain
+ * compilers when operating with pointers declared with the const type qual-
+ * ifier in a context without such qualifier. Examples include passing a
+ * pointer declared with the const qualifier to a function without such
+ * qualifier, and variable assignment from a const pointer to a non-const
+ * pointer.
+ *
+ * As the macro may hide valid errors, their usage is not recommended
+ * unless there is a well-thought reason for a cast. A typical use case for
+ * __UNCONST() involve an API that does not follow the so-called ``const
+ * correctness'' even if it would be appropriate.
*/
-#define DE_CONST(konst, var) \
- do { \
- union { \
- const void *k; \
- void *v; \
- } _u; \
- _u.k = konst; \
- var = _u.v; \
- } while (0)
+#define UNCONST(ptr) ((void *)(uintptr_t)(ptr))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
* but in isc_log_createchannel it gets copied
* into writable memory and is not longer truly const.
*/
- DE_CONST(FILE_NAME(channel), filename);
+ filename = UNCONST(FILE_NAME(channel));
isc_mem_free(mctx, filename);
if (FILE_STREAM(channel) != NULL) {
* The name pointer points to the next array.
* Ick.
*/
- DE_CONST(catp->name, catp);
+ catp = UNCONST(catp->name);
} else {
catp++;
}
* catp is neither modified nor returned to the
* caller, so removing its const qualifier is ok.
*/
- DE_CONST(catp->name, catp);
+ catp = UNCONST(catp->name);
} else {
if (strcmp(catp->name, name) == 0) {
return (catp);
* The name pointer points to the next array.
* Ick.
*/
- DE_CONST(modp->name, modp);
+ modp = UNCONST(modp->name);
} else {
modp++;
}
* modp is neither modified nor returned to the
* caller, so removing its const qualifier is ok.
*/
- DE_CONST(modp->name, modp);
+ modp = UNCONST(modp->name);
} else {
if (strcmp(modp->name, name) == 0) {
return (modp);
char sep = '/';
/*
- * It is safe to DE_CONST the file.name because it was copied
+ * It is safe to UNCONST the file.name because it was copied
* with isc_mem_strdup().
*/
bname = strrchr(file->name, sep);
*bname++ = '\0';
dirname = file->name;
} else {
- DE_CONST(file->name, bname);
+ bname = UNCONST(file->name);
dirname = ".";
}
bnamelen = strlen(bname);
char sep = '/';
/*
- * It is safe to DE_CONST the file.name because it was copied
+ * It is safe to UNCONST the file.name because it was copied
* with isc_mem_strdup().
*/
bname = strrchr(file->name, sep);
*bname++ = '\0';
dirname = file->name;
} else {
- DE_CONST(file->name, bname);
+ bname = UNCONST(file->name);
dirname = ".";
}
bnamelen = strlen(bname);
void
isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s) {
- isc_netaddr_t *src;
-
- DE_CONST(s, src); /* Must come before IN6_IS_ADDR_V4MAPPED. */
+ isc_netaddr_t *src = UNCONST(s); /* Must come before
+ IN6_IS_ADDR_V4MAPPED. */
REQUIRE(s->family == AF_INET6);
REQUIRE(IN6_IS_ADDR_V4MAPPED(&src->type.in6));
* truly const coming in and then the caller modified it anyway ...
* well, don't do that!
*/
- DE_CONST(key, elt->key);
+ elt->key = UNCONST(key);
elt->type = type;
elt->value = value;
char *
isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) {
- char c, *ret;
+ char c;
const char *bp;
size_t len = 0;
int alt_format, i, split_year = 0;
}
/* LINTED functional specification */
- DE_CONST(bp, ret);
- return (ret);
+ return (UNCONST(bp));
}
isccc_region_t r;
len = strlen(str);
- DE_CONST(str, r.rstart);
+ r.rstart = UNCONST(str);
r.rend = r.rstart + len;
return (isccc_alist_definebinary(alist, key, &r));
*/
memset(&loop, 0, sizeof(loop));
ISC_LINK_INIT(&loop, nextincache);
- DE_CONST(aclname, loop.name);
+ loop.name = UNCONST(aclname);
loop.magic = LOOP_MAGIC;
ISC_LIST_APPEND(ctx->named_acl_cache, &loop, nextincache);
result = cfg_acl_fromconfig(cacl, cctx, lctx, ctx, mctx, nest_level,
dns_fixedname_init(&fixed);
obj = cfg_tuple_get(ent, "class");
if (cfg_obj_isstring(obj)) {
- DE_CONST(cfg_obj_asstring(obj), r.base);
+ r.base = UNCONST(cfg_obj_asstring(obj));
r.length = strlen(r.base);
tresult = dns_rdataclass_fromtext(&rdclass, &r);
if (tresult != ISC_R_SUCCESS) {
obj = cfg_tuple_get(ent, "type");
if (cfg_obj_isstring(obj)) {
- DE_CONST(cfg_obj_asstring(obj), r.base);
+ r.base = UNCONST(cfg_obj_asstring(obj));
r.length = strlen(r.base);
tresult = dns_rdatatype_fromtext(&rdtype, &r);
if (tresult != ISC_R_SUCCESS) {
isc_textregion_t r;
dns_secalg_t alg;
- DE_CONST(cfg_obj_asstring(cfg_listelt_value(element)), r.base);
+ r.base = UNCONST(cfg_obj_asstring(cfg_listelt_value(element)));
r.length = strlen(r.base);
tresult = dns_secalg_fromtext(&alg, &r);
isc_textregion_t r;
dns_dsdigest_t digest;
- DE_CONST(cfg_obj_asstring(cfg_listelt_value(element)), r.base);
+ r.base = UNCONST(cfg_obj_asstring(cfg_listelt_value(element)));
r.length = strlen(r.base);
/* works with a numeric argument too */
isc_symtab_t *symtab = NULL;
isc_symvalue_t symvalue;
const cfg_listelt_t *element;
- const cfg_listelt_t **stack = NULL;
+ cfg_listelt_t **stack = NULL;
uint32_t stackcount = 0, pushed = 0;
const cfg_obj_t *listobj;
oldsize = stackcount * sizeof(*stack);
newstack = isc_mem_get(mctx, newsize);
if (stackcount != 0) {
- void *ptr;
-
- DE_CONST(stack, ptr);
memmove(newstack, stack, oldsize);
- isc_mem_put(mctx, ptr, oldsize);
+ isc_mem_put(mctx, stack, oldsize);
}
stack = newstack;
stackcount = newlen;
}
- stack[pushed++] = cfg_list_next(element);
+ stack[pushed++] = UNCONST(cfg_list_next(element));
goto newlist;
}
if (pushed != 0) {
goto resume;
}
if (stack != NULL) {
- void *ptr;
-
- DE_CONST(stack, ptr);
- isc_mem_put(mctx, ptr, stackcount * sizeof(*stack));
+ isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
}
isc_symtab_destroy(&symtab);
*countp = count;
case dns_ssumatchtype_external:
case dns_ssumatchtype_local:
if (tresult == ISC_R_SUCCESS) {
- DE_CONST(str, r.base);
+ r.base = UNCONST(str);
r.length = strlen(str);
tresult = dns_rdatatype_fromtext(&type, &r);
}
const char *bracket;
typeobj = cfg_listelt_value(element2);
- DE_CONST(cfg_obj_asstring(typeobj), r.base);
+ r.base = UNCONST(cfg_obj_asstring(typeobj));
bracket = strchr(r.base, '(' /*)*/);
if (bracket != NULL) {
if (cfg_obj_isstring(obj)) {
isc_textregion_t r;
- DE_CONST(cfg_obj_asstring(obj), r.base);
+ r.base = UNCONST(cfg_obj_asstring(obj));
r.length = strlen(r.base);
result = dns_rdataclass_fromtext(&zclass, &r);
if (result != ISC_R_SUCCESS) {
if (cfg_obj_isstring(vclassobj)) {
isc_textregion_t r;
- DE_CONST(cfg_obj_asstring(vclassobj), r.base);
+ r.base = UNCONST(cfg_obj_asstring(vclassobj));
r.length = strlen(r.base);
tresult = dns_rdataclass_fromtext(&vclass, &r);
if (tresult != ISC_R_SUCCESS) {
isc_result_t result;
isc_textregion_t tr;
- DE_CONST(str, tr.base);
+ tr.base = UNCONST(str);
tr.length = strlen(tr.base);
result = isccfg_parse_duration(&tr, &duration);
if (result == ISC_R_SUCCESS) {
dns_dsdigest_t alg;
const char *str = cfg_obj_asstring(digest);
- DE_CONST(str, r.base);
+ r.base = UNCONST(str);
r.length = strlen(str);
result = dns_dsdigest_fromtext(&alg, &r);
if (result != ISC_R_SUCCESS) {
static dns_fixedname_t fname;
static dns_name_t *name;
static isc_buffer_t namebuf;
- void *deconst_namestr;
name = dns_fixedname_initname(&fname);
- DE_CONST(namestr, deconst_namestr); /* OK, since we don't modify it */
- isc_buffer_init(&namebuf, deconst_namestr, strlen(deconst_namestr));
+ isc_buffer_init(&namebuf, UNCONST(namestr), strlen(namestr));
isc_buffer_add(&namebuf, strlen(namestr));
assert_int_equal(
dns_name_fromtext(name, &namebuf, dns_rootname, 0, NULL),
if (from.salt == NULL) {
to->salt = NULL;
} else if (strcmp(from.salt, "-") == 0) {
- DE_CONST("-", to->salt);
+ to->salt = (unsigned char *)"-";
} else {
decode_salt(from.salt, saltbuf, saltlen);
to->salt = saltbuf;