From a179ca6707b29cfc01371fb5636b2f49d263ab83 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Mon, 15 Jan 2024 17:39:43 +1100 Subject: treewide: Make a bunch of pointer variables pointers to const Sufficiently recent cppcheck (I'm using 2.13.0) seems to have added another warning for pointer variables which could be pointer to const but aren't. Use this to make a bunch of variables const pointers where they previously weren't for no particular reason. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- conf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'conf.c') diff --git a/conf.c b/conf.c index ad2a093..5e15b66 100644 --- a/conf.c +++ b/conf.c @@ -412,8 +412,9 @@ static void get_dns(struct ctx *c) int dns4_set, dns6_set, dnss_set, dns_set, fd; struct fqdn *s = c->dns_search; struct lineread resolvconf; + char *line, *end; + const char *p; int line_len; - char *line, *p, *end; dns4_set = !c->ifi4 || !IN4_IS_ADDR_UNSPECIFIED(dns4); dns6_set = !c->ifi6 || !IN6_IS_ADDR_UNSPECIFIED(dns6); @@ -1025,7 +1026,7 @@ static int conf_runas(char *opt, unsigned int *uid, unsigned int *gid) if (*endptr) { #ifndef GLIBC_NO_STATIC_NSS /* Not numeric, look up as a username */ - struct passwd *pw; + const struct passwd *pw; /* cppcheck-suppress getpwnamCalled */ if (!(pw = getpwnam(uopt)) || !(*uid = pw->pw_uid)) return -ENOENT; @@ -1042,7 +1043,7 @@ static int conf_runas(char *opt, unsigned int *uid, unsigned int *gid) if (*endptr) { #ifndef GLIBC_NO_STATIC_NSS /* Not numeric, look up as a group name */ - struct group *gr; + const struct group *gr; /* cppcheck-suppress getgrnamCalled */ if (!(gr = getgrnam(gopt))) return -ENOENT; @@ -1086,7 +1087,7 @@ static void conf_ugid(char *runas, uid_t *uid, gid_t *gid) warn("Don't run as root. Changing to nobody..."); { #ifndef GLIBC_NO_STATIC_NSS - struct passwd *pw; + const struct passwd *pw; /* cppcheck-suppress getpwnamCalled */ pw = getpwnam("nobody"); if (!pw) { @@ -1173,14 +1174,15 @@ void conf(struct ctx *c, int argc, char **argv) bool copy_addrs_opt = false, copy_routes_opt = false; enum port_fwd_mode fwd_default = FWD_NONE; bool v4_only = false, v6_only = false; - char *runas = NULL, *logfile = NULL; struct in6_addr *dns6 = c->ip6.dns; struct fqdn *dnss = c->dns_search; struct in_addr *dns4 = c->ip4.dns; unsigned int ifi4 = 0, ifi6 = 0; + const char *logfile = NULL; const char *optstring; int name, ret, b, i; size_t logsize = 0; + char *runas = NULL; uid_t uid; gid_t gid; -- cgit v1.2.3