[PATCH] cppcheck: fix clarifyCalculation issue
yegorslists
Tue Aug 20 10:36:08 2019From: Yegor Yefremov <yegorslists@xxxxxxxxxxxxxx>
This fix clarifies calculation precedence for '&' and '?'.
---
src/dhcp.c | 4 ++--
src/dhcpcd.c | 14 +++++++-------
src/if-linux.c | 4 ++--
src/ipv6.c | 4 ++--
src/logerr.c | 2 +-
src/route.c | 4 ++--
src/script.c | 2 +-
7 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/dhcp.c b/src/dhcp.c
index 245ad5c4..4f477249 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -1732,7 +1732,7 @@ send_message(struct interface *ifp, uint8_t type,
goto fail;
logdebugx("%s: sending %s (xid 0x%x), next in %0.1f seconds",
ifp->name,
- ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type),
+ (ifo->options & DHCPCD_BOOTP) ? "BOOTP" : get_dhcp_op(type),
state->xid,
timespec_to_double(&tv));
}
@@ -1857,7 +1857,7 @@ dhcp_discover(void *arg)
ifp->name, inet_ntoa(ifo->req_addr));
else
loginfox("%s: soliciting a %s lease",
- ifp->name, ifo->options & DHCPCD_BOOTP ? "BOOTP" : "DHCP");
+ ifp->name, (ifo->options & DHCPCD_BOOTP) ? "BOOTP" : "DHCP");
send_discover(ifp);
}
diff --git a/src/dhcpcd.c b/src/dhcpcd.c
index bddd316b..f71433d8 100644
--- a/src/dhcpcd.c
+++ b/src/dhcpcd.c
@@ -1617,7 +1617,7 @@ main(int argc, char **argv)
logopts = LOGERR_ERR|LOGERR_LOG|LOGERR_LOG_DATE|LOGERR_LOG_PID;
i = 0;
while ((opt = getopt_long(argc, argv,
- ctx.options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS,
+ (ctx.options & DHCPCD_PRINT_PIDFILE) ? NOERR_IF_OPTS : IF_OPTS,
cf_options, &oi)) != -1)
{
switch (opt) {
@@ -1969,7 +1969,7 @@ printpidfile:
}
#else
if (control_start(&ctx,
- ctx.options & DHCPCD_MASTER ? NULL : argv[optind]) == -1)
+ (ctx.options & DHCPCD_MASTER) ? NULL : argv[optind]) == -1)
{
logerr("%s: control_start", __func__);
goto exit_failure;
@@ -1981,9 +1981,9 @@ printpidfile:
#ifdef HAVE_SETPROCTITLE
setproctitle("%s%s%s",
- ctx.options & DHCPCD_MASTER ? "[master]" : argv[optind],
- ctx.options & DHCPCD_IPV4 ? " [ip4]" : "",
- ctx.options & DHCPCD_IPV6 ? " [ip6]" : "");
+ (ctx.options & DHCPCD_MASTER) ? "[master]" : argv[optind],
+ (ctx.options & DHCPCD_IPV4) ? " [ip4]" : "",
+ (ctx.options & DHCPCD_IPV6) ? " [ip6]" : "");
#endif
if (if_opensockets(&ctx) == -1) {
@@ -2028,7 +2028,7 @@ printpidfile:
if (ctx.ifc == 0) {
logfunc_t *logfunc;
- logfunc = ctx.options & DHCPCD_INACTIVE ?
+ logfunc = (ctx.options & DHCPCD_INACTIVE) ?
logdebugx : logerrx;
logfunc("no valid interfaces found");
} else
@@ -2076,7 +2076,7 @@ printpidfile:
{
logfunc_t *logfunc;
- logfunc = ctx.options & DHCPCD_INACTIVE ?
+ logfunc = (ctx.options & DHCPCD_INACTIVE) ?
logdebugx : logwarnx;
logfunc("no interfaces have a carrier");
if (dhcpcd_daemonise(&ctx))
diff --git a/src/if-linux.c b/src/if-linux.c
index b7e84eb5..9cb87586 100644
--- a/src/if-linux.c
+++ b/src/if-linux.c
@@ -357,7 +357,7 @@ if_carrier(struct interface *ifp)
if (if_getflags(ifp) == -1)
return LINK_UNKNOWN;
- return ifp->flags & IFF_RUNNING ? LINK_UP : LINK_DOWN;
+ return (ifp->flags & IFF_RUNNING) ? LINK_UP : LINK_DOWN;
}
static int
@@ -816,7 +816,7 @@ link_netlink(struct dhcpcd_ctx *ctx, void *arg, struct nlmsghdr *nlm)
}
dhcpcd_handlecarrier(ctx,
- ifi->ifi_flags & IFF_RUNNING ? LINK_UP : LINK_DOWN,
+ (ifi->ifi_flags & IFF_RUNNING) ? LINK_UP : LINK_DOWN,
ifi->ifi_flags, ifn);
return 0;
}
diff --git a/src/ipv6.c b/src/ipv6.c
index 31a0cae0..3a8ec015 100644
--- a/src/ipv6.c
+++ b/src/ipv6.c
@@ -684,10 +684,10 @@ ipv6_addaddr1(struct ipv6_addr *ia, const struct timespec *now)
}
}
- logfunc = ia->flags & IPV6_AF_NEW ? loginfox : logdebugx;
+ logfunc = (ia->flags & IPV6_AF_NEW) ? loginfox : logdebugx;
logfunc("%s: adding %saddress %s", ifp->name,
#ifdef IPV6_AF_TEMPORARY
- ia->flags & IPV6_AF_TEMPORARY ? "temporary " : "",
+ (ia->flags & IPV6_AF_TEMPORARY) ? "temporary " : "",
#else
"",
#endif
diff --git a/src/logerr.c b/src/logerr.c
index 59f8cb61..21431f97 100644
--- a/src/logerr.c
+++ b/src/logerr.c
@@ -330,7 +330,7 @@ logsetopts(unsigned int opts)
struct logctx *ctx = &_logctx;
ctx->log_opts = opts;
- setlogmask(LOG_UPTO(opts & LOGERR_DEBUG ? LOG_DEBUG : LOG_INFO));
+ setlogmask(LOG_UPTO((opts & LOGERR_DEBUG) ? LOG_DEBUG : LOG_INFO));
}
#ifdef LOGERR_TAG
diff --git a/src/route.c b/src/route.c
index c1d19eb0..ec2a6d7a 100644
--- a/src/route.c
+++ b/src/route.c
@@ -265,12 +265,12 @@ rt_desc(const char *cmd, const struct rt *rt)
} else if (gateway_unspec)
loginfox("%s: %s%s route to %s/%d",
ifname, cmd,
- rt->rt_flags & RTF_REJECT ? " reject" : "",
+ (rt->rt_flags & RTF_REJECT) ? " reject" : "",
dest, prefix);
else
loginfox("%s: %s%s route to %s/%d via %s",
ifname, cmd,
- rt->rt_flags & RTF_REJECT ? " reject" : "",
+ (rt->rt_flags & RTF_REJECT) ? " reject" : "",
dest, prefix, gateway);
}
diff --git a/src/script.c b/src/script.c
index 3cb33b6e..7db8254b 100644
--- a/src/script.c
+++ b/src/script.c
@@ -318,7 +318,7 @@ make_env(const struct interface *ifp, const char *reason)
if (efprintf(fp, "if_up=false") == -1)
goto eexit;
if (efprintf(fp, "if_down=%s",
- ifo->options & DHCPCD_RELEASE ? "true" : "false") == -1)
+ (ifo->options & DHCPCD_RELEASE) ? "true" : "false") == -1)
goto eexit;
} else if (strcmp(reason, "TEST") == 0 ||
strcmp(reason, "PREINIT") == 0 ||
--
2.17.0
Archive administrator: postmaster@marples.name