From: Ondřej Surý Date: Thu, 30 Mar 2023 20:34:12 +0000 (+0200) Subject: Replace DE_CONST(k, v) with v = UNCONST(k) macro X-Git-Tag: v9.19.12~35^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a6a0fa867aad195efa9ca0ea61e955818515939;p=thirdparty%2Fbind9.git Replace DE_CONST(k, v) with v = UNCONST(k) macro Replace the complicated DE_CONST macro that required union with much simple reference-dereference trick in the UNCONST() macro. --- diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index 6087f112493..77aecccc70e 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -616,7 +616,7 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename, 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)); diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 4a25acb2def..19f672224e4 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -155,7 +155,7 @@ configure_hint(const char *zfile, const char *zclass, isc_mem_t *mctx) { 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) { @@ -510,7 +510,7 @@ config_getclass(const cfg_obj_t *classobj, dns_rdataclass_t defclass, *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)); } diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 82cb3d00d11..c038ab32525 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -1962,7 +1962,7 @@ addnsec3param(const unsigned char *salt, size_t salt_len, 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, @@ -2811,7 +2811,7 @@ build_final_keylist(void) { char *s; size_t dlen; - DE_CONST(sync_records, digest); + digest = UNCONST(sync_records); next_digest: s = strchr(digest, delim); if (s == NULL) { diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index 62c74765591..0bf8cc78269 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -376,7 +376,7 @@ strtoclass(const char *str) { 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) { @@ -391,7 +391,7 @@ strtodsdigest(const char *str) { 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) { diff --git a/bin/named/builtin.c b/bin/named/builtin.c index b0767a1e52f..f2e6f2ed755 100644 --- a/bin/named/builtin.c +++ b/bin/named/builtin.c @@ -126,7 +126,7 @@ putrdata(bdbnode_t *node, dns_rdatatype_t typeval, dns_ttl_t ttl, 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); diff --git a/bin/named/config.c b/bin/named/config.c index b470486df46..2149b29b859 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -441,7 +441,7 @@ named_config_getclass(const cfg_obj_t *classobj, dns_rdataclass_t defclass, *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) { @@ -461,7 +461,7 @@ named_config_gettype(const cfg_obj_t *typeobj, dns_rdatatype_t deftype, *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) { diff --git a/bin/named/server.c b/bin/named/server.c index 47174867a71..593163ffe50 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -1674,7 +1674,7 @@ disable_algorithms(const cfg_obj_t *disabled, dns_resolver_t *resolver) { 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); @@ -1717,7 +1717,7 @@ disable_ds_digests(const cfg_obj_t *disabled, dns_resolver_t *resolver) { 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. */ @@ -8488,8 +8488,7 @@ load_configuration(const char *filename, named_server_t *server, 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; @@ -12683,7 +12682,7 @@ nzf_writeconf(const cfg_obj_t *config, dns_view_t *view) { CHECK(ISC_R_FAILURE); } - DE_CONST(&zl->value.list, list); + list = UNCONST(&zl->value.list); CHECK(add_comment(fp, view->name)); /* force a comment */ @@ -13371,7 +13370,7 @@ delete_zoneconf(dns_view_t *view, cfg_parser_t *pctx, const cfg_obj_t *config, CHECK(ISC_R_FAILURE); } - DE_CONST(&zl->value.list, list); + list = UNCONST(&zl->value.list); myname = dns_fixedname_initname(&myfixed); @@ -13388,7 +13387,7 @@ delete_zoneconf(dns_view_t *view, cfg_parser_t *pctx, const cfg_obj_t *config, 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)); @@ -13517,8 +13516,7 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, 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")); } @@ -13761,7 +13759,7 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, #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 */ diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c index 45b00d57107..7c924b1f86f 100644 --- a/bin/named/statschannel.c +++ b/bin/named/statschannel.c @@ -3300,7 +3300,7 @@ render_json(uint32_t flags, void *arg, unsigned int *retcode, *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; @@ -3442,7 +3442,7 @@ render_xsl(const isc_httpd_t *httpd, const isc_httpdurl_t *urlinfo, void *args, 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: diff --git a/bin/named/zoneconf.c b/bin/named/zoneconf.c index f7184f4c865..9e392eb25aa 100644 --- a/bin/named/zoneconf.c +++ b/bin/named/zoneconf.c @@ -305,7 +305,7 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone, 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) { diff --git a/contrib/dlz/modules/include/dlz_minimal.h b/contrib/dlz/modules/include/dlz_minimal.h index 32f0f12f936..f2a69e40b89 100644 --- a/contrib/dlz/modules/include/dlz_minimal.h +++ b/contrib/dlz/modules/include/dlz_minimal.h @@ -75,15 +75,8 @@ typedef uint32_t dns_ttl_t; /* 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 diff --git a/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c b/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c index 95221a1e5ef..2bb69759913 100644 --- a/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c +++ b/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c @@ -44,16 +44,6 @@ #include #include -#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. */ @@ -119,7 +109,7 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) { 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'", @@ -235,8 +225,8 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, 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)) { @@ -315,7 +305,7 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) { 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'", diff --git a/lib/dns/dnstap.c b/lib/dns/dnstap.c index bb616ea08be..e2fcc9ef97e 100644 --- a/lib/dns/dnstap.c +++ b/lib/dns/dnstap.c @@ -997,7 +997,7 @@ dns_dt_getframe(dns_dthandle_t *handle, uint8_t **bufp, size_t *sizep) { 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); diff --git a/lib/dns/rdata/generic/txt_16.c b/lib/dns/rdata/generic/txt_16.c index 3acd66abdd4..ce202496860 100644 --- a/lib/dns/rdata/generic/txt_16.c +++ b/lib/dns/rdata/generic/txt_16.c @@ -30,7 +30,7 @@ generic_fromtext_txt(ARGS_FROMTEXT) { 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++; diff --git a/lib/dns/tsig.c b/lib/dns/tsig.c index f4278de865f..888c1a4fb19 100644 --- a/lib/dns/tsig.c +++ b/lib/dns/tsig.c @@ -365,8 +365,7 @@ cleanup_refs: 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); } @@ -719,8 +718,7 @@ tsigkey_free(dns_tsigkey_t *key) { 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)); } diff --git a/lib/dns/view.c b/lib/dns/view.c index fdfc295239f..9c3995c6ac9 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -2328,7 +2328,7 @@ isc_result_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; @@ -2338,8 +2338,6 @@ dns_view_addtrustedkey(dns_view_t *view, dns_rdatatype_t rdtype, 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; diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 450af4b6793..3fd2783009f 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -2595,8 +2595,7 @@ zone_startload(dns_db_t *db, dns_zone_t *zone, isc_time_t loadtime) { 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); @@ -21567,7 +21566,7 @@ dns_zone_keydone(dns_zone_t *zone, const char *keystr) { 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)); } @@ -22011,7 +22010,7 @@ setparam: } 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]; diff --git a/lib/dns/zoneverify.c b/lib/dns/zoneverify.c index bf2b7cc68ea..7709ed8d8ae 100644 --- a/lib/dns/zoneverify.c +++ b/lib/dns/zoneverify.c @@ -1079,21 +1079,21 @@ _checknext(const vctx_t *vctx, const struct nsec3_chain_fixed *first, 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); diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index ba74a678e7f..eb99583e209 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -80,22 +80,19 @@ #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])) diff --git a/lib/isc/log.c b/lib/isc/log.c index dacdafaf8fd..a24e1c37fef 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -456,7 +456,7 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) { * 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) { @@ -522,7 +522,7 @@ isc_log_registercategories(isc_log_t *lctx, isc_logcategory_t categories[]) { * The name pointer points to the next array. * Ick. */ - DE_CONST(catp->name, catp); + catp = UNCONST(catp->name); } else { catp++; } @@ -553,7 +553,7 @@ isc_log_categorybyname(isc_log_t *lctx, const char *name) { * 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); @@ -593,7 +593,7 @@ isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]) { * The name pointer points to the next array. * Ick. */ - DE_CONST(modp->name, modp); + modp = UNCONST(modp->name); } else { modp++; } @@ -624,7 +624,7 @@ isc_log_modulebyname(isc_log_t *lctx, const char *name) { * 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); @@ -1020,7 +1020,7 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) { 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); @@ -1028,7 +1028,7 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) { *bname++ = '\0'; dirname = file->name; } else { - DE_CONST(file->name, bname); + bname = UNCONST(file->name); dirname = "."; } bnamelen = strlen(bname); @@ -1152,7 +1152,7 @@ remove_old_tsversions(isc_logfile_t *file, int versions) { 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); @@ -1160,7 +1160,7 @@ remove_old_tsversions(isc_logfile_t *file, int versions) { *bname++ = '\0'; dirname = file->name; } else { - DE_CONST(file->name, bname); + bname = UNCONST(file->name); dirname = "."; } bnamelen = strlen(bname); diff --git a/lib/isc/netaddr.c b/lib/isc/netaddr.c index 527546eb208..29d5e6834b6 100644 --- a/lib/isc/netaddr.c +++ b/lib/isc/netaddr.c @@ -439,9 +439,8 @@ isc_netaddr_isnetzero(const isc_netaddr_t *na) { 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)); diff --git a/lib/isc/symtab.c b/lib/isc/symtab.c index fd507ab9188..c4cbcabbbe6 100644 --- a/lib/isc/symtab.c +++ b/lib/isc/symtab.c @@ -243,7 +243,7 @@ isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type, * 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; diff --git a/lib/isc/tm.c b/lib/isc/tm.c index 65694a0a623..eafa1187906 100644 --- a/lib/isc/tm.c +++ b/lib/isc/tm.c @@ -135,7 +135,7 @@ isc_tm_timegm(struct tm *tm) { 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; @@ -463,6 +463,5 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) { } /* LINTED functional specification */ - DE_CONST(bp, ret); - return (ret); + return (UNCONST(bp)); } diff --git a/lib/isccc/cc.c b/lib/isccc/cc.c index 4fec7f567b0..58fb86e6e2c 100644 --- a/lib/isccc/cc.c +++ b/lib/isccc/cc.c @@ -855,7 +855,7 @@ isccc_cc_definestring(isccc_sexpr_t *alist, const char *key, const char *str) { 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)); diff --git a/lib/isccfg/aclconf.c b/lib/isccfg/aclconf.c index 3f2c6994ee0..77154b14df7 100644 --- a/lib/isccfg/aclconf.c +++ b/lib/isccfg/aclconf.c @@ -152,7 +152,7 @@ convert_named_acl(const cfg_obj_t *nameobj, const cfg_obj_t *cctx, */ 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, diff --git a/lib/isccfg/check.c b/lib/isccfg/check.c index dc7936e8db0..b0553779130 100644 --- a/lib/isccfg/check.c +++ b/lib/isccfg/check.c @@ -104,7 +104,7 @@ check_orderent(const cfg_obj_t *ent, isc_log_t *logctx) { 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) { @@ -118,7 +118,7 @@ check_orderent(const cfg_obj_t *ent, isc_log_t *logctx) { 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) { @@ -389,7 +389,7 @@ disabled_algorithms(const cfg_obj_t *disabled, isc_log_t *logctx) { 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); @@ -434,7 +434,7 @@ disabled_ds_digests(const cfg_obj_t *disabled, isc_log_t *logctx) { 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 */ @@ -2402,7 +2402,7 @@ validate_remotes(const char *list, const cfg_obj_t *obj, 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; @@ -2519,16 +2519,13 @@ resume: 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) { @@ -2536,10 +2533,7 @@ resume: 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; @@ -2665,7 +2659,7 @@ check_update_policy(const cfg_obj_t *policy, isc_log_t *logctx) { 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); } @@ -2689,7 +2683,7 @@ check_update_policy(const cfg_obj_t *policy, isc_log_t *logctx) { 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) { @@ -2969,7 +2963,7 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, 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) { @@ -6019,7 +6013,7 @@ isccfg_check_namedconf(const cfg_obj_t *config, unsigned int flags, 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) { diff --git a/lib/isccfg/kaspconf.c b/lib/isccfg/kaspconf.c index 4e384e0470f..e0d362870f0 100644 --- a/lib/isccfg/kaspconf.c +++ b/lib/isccfg/kaspconf.c @@ -63,7 +63,7 @@ parse_duration(const char *str) { 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) { @@ -332,7 +332,7 @@ add_digest(dns_kasp_t *kasp, const cfg_obj_t *digest, isc_log_t *logctx) { 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) { diff --git a/tests/dns/keytable_test.c b/tests/dns/keytable_test.c index ac8ae028689..eea42150bd2 100644 --- a/tests/dns/keytable_test.c +++ b/tests/dns/keytable_test.c @@ -91,11 +91,9 @@ str2name(const char *namestr) { 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), diff --git a/tests/dns/nsec3param_test.c b/tests/dns/nsec3param_test.c index 21879da0234..84d1b4cad0f 100644 --- a/tests/dns/nsec3param_test.c +++ b/tests/dns/nsec3param_test.c @@ -78,7 +78,7 @@ copy_params(nsec3param_rdata_test_params_t from, dns_rdata_nsec3param_t *to, 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;