From: Mark Andrews Date: Fri, 19 Dec 2025 01:32:33 +0000 (+1100) Subject: Use const pointer with strchr of const pointer X-Git-Tag: v9.21.18~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af379e10ccbede22a38cdbee58c6a71c097221d2;p=thirdparty%2Fbind9.git Use const pointer with strchr of const pointer C23 now has qualifier preserving standard functions for strchr, bsearch, strpbrk, strrchr, strstr, memchr. There where a few places where the return value was not assigned to a const qualified pointer. These have been fixed. --- diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 0d69fb79d35..c149eedaf4a 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -1754,7 +1754,7 @@ append_str(const char *text, int len, char **p, char *end) { static isc_result_t reverse_octets(const char *in, char **p, char *end) { - char *dot = strchr(in, '.'); + const char *dot = strchr(in, '.'); int len; if (dot != NULL) { RETERR(reverse_octets(dot + 1, p, end)); diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index 4a25eeecf8c..6240401bb36 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -1605,7 +1605,7 @@ static bool dash_option(const char *option, char *next, struct query *query, bool global, bool *setname) { char opt; - const char *value; + const char *value, *oldvalue; isc_result_t result; bool value_from_next; isc_consttextregion_t tr; @@ -1615,7 +1615,7 @@ dash_option(const char *option, char *next, struct query *query, bool global, struct in_addr in4; struct in6_addr in6; in_port_t srcport; - char *hash; + const char *hash; uint32_t num; while (strpbrk(option, single_dash_opts) == &option[0]) { @@ -1685,12 +1685,15 @@ dash_option(const char *option, char *next, struct query *query, bool global, case 'b': GLOBAL(); hash = strchr(value, '#'); + oldvalue = value; if (hash != NULL) { result = parse_uint(&num, hash + 1, MAXPORT, "port number"); CHECKM("parse_uint(srcport)", result); srcport = num; - *hash = '\0'; + snprintf(textname, sizeof(textname), "%.*s", + (int)(hash - value), value); + value = textname; } else { srcport = 0; } @@ -1701,13 +1704,7 @@ dash_option(const char *option, char *next, struct query *query, bool global, isc_sockaddr_fromin(&srcaddr, &in4, srcport); isc_net_disableipv6(); } else { - if (hash != NULL) { - *hash = '#'; - } - fatal("invalid address %s", value); - } - if (hash != NULL) { - *hash = '#'; + fatal("invalid address %s", oldvalue); } have_src = true; return value_from_next; diff --git a/lib/isc/file.c b/lib/isc/file.c index fbf0b80fb1f..d01bf390cfa 100644 --- a/lib/isc/file.c +++ b/lib/isc/file.c @@ -353,7 +353,7 @@ isc_file_openuniquemode(char *templet, int mode, FILE **fp) { return isc__errno2result(errno); } for (cp = x;;) { - char *t; + const char *t; if (*cp == '\0') { return ISC_R_FAILURE; }