diff options
author | dim <dim@FreeBSD.org> | 2014-11-22 23:04:33 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2014-11-22 23:04:33 +0000 |
commit | abfc69102bd74f26f145800e55f2511c69558425 (patch) | |
tree | fd2567b67bc4bd09afaea79e3c0a2c7d55e7f276 /usr.sbin | |
parent | e0039d6e26f32b23a14cbfd778e66baef81736b0 (diff) | |
download | FreeBSD-src-abfc69102bd74f26f145800e55f2511c69558425.zip FreeBSD-src-abfc69102bd74f26f145800e55f2511c69558425.tar.gz |
Fix the following -Werror warnings from clang 3.5.0, while building
usr.sbin/rtadvd:
usr.sbin/rtadvd/rtadvd.c:1291:7: error: taking the absolute value of unsigned type 'unsigned int' has no effect [-Werror,-Wabsolute-value]
abs(preferred_time - pfx->pfx_pltimeexpire) > rai->rai_clockskew) {
^
usr.sbin/rtadvd/rtadvd.c:1291:7: note: remove the call to 'abs' since unsigned values cannot be negative
abs(preferred_time - pfx->pfx_pltimeexpire) > rai->rai_clockskew) {
^~~
usr.sbin/rtadvd/rtadvd.c:1324:7: error: taking the absolute value of unsigned type 'unsigned int' has no effect [-Werror,-Wabsolute-value]
abs(valid_time - pfx->pfx_vltimeexpire) > rai->rai_clockskew) {
^
usr.sbin/rtadvd/rtadvd.c:1324:7: note: remove the call to 'abs' since unsigned values cannot be negative
abs(valid_time - pfx->pfx_vltimeexpire) > rai->rai_clockskew) {
^~~
2 errors generated.
These warnings occur because both preferred_time and pfx_pltimeexpire
are uint32_t's, so the subtraction expression is also unsigned, and
calling abs() is a no-op.
However, the intention was to look at the absolute difference between
the two unsigned quantities. Introduce a small static function to
clarify what we're doing, and call that instead.
Reviewed by: hrs
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D1197
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c index ba71954..6554b61 100644 --- a/usr.sbin/rtadvd/rtadvd.c +++ b/usr.sbin/rtadvd/rtadvd.c @@ -1230,6 +1230,12 @@ ra_input(int len, struct nd_router_advert *nra, return; } +static uint32_t +udiff(uint32_t u, uint32_t v) +{ + return (u >= v ? u - v : v - u); +} + /* return a non-zero value if the received prefix is inconsitent with ours */ static int prefix_check(struct nd_opt_prefix_info *pinfo, @@ -1288,7 +1294,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo, preferred_time += now.tv_sec; if (!pfx->pfx_timer && rai->rai_clockskew && - abs(preferred_time - pfx->pfx_pltimeexpire) > rai->rai_clockskew) { + udiff(preferred_time, pfx->pfx_pltimeexpire) > rai->rai_clockskew) { syslog(LOG_INFO, "<%s> preferred lifetime for %s/%d" " (decr. in real time) inconsistent on %s:" @@ -1321,7 +1327,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo, valid_time += now.tv_sec; if (!pfx->pfx_timer && rai->rai_clockskew && - abs(valid_time - pfx->pfx_vltimeexpire) > rai->rai_clockskew) { + udiff(valid_time, pfx->pfx_vltimeexpire) > rai->rai_clockskew) { syslog(LOG_INFO, "<%s> valid lifetime for %s/%d" " (decr. in real time) inconsistent on %s:" |