summaryrefslogtreecommitdiffstats
path: root/usr.sbin/rtadvd
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2014-11-25 13:12:45 +0000
committerdim <dim@FreeBSD.org>2014-11-25 13:12:45 +0000
commit10bfcc72ff17ef32e5b2e365e2c2ac6687813ae0 (patch)
tree4f4854d74bce52d560c45b3cdf55320cea81f304 /usr.sbin/rtadvd
parentb7c69c9f14252044345f8178d764a2dbc054cebd (diff)
downloadFreeBSD-src-10bfcc72ff17ef32e5b2e365e2c2ac6687813ae0.zip
FreeBSD-src-10bfcc72ff17ef32e5b2e365e2c2ac6687813ae0.tar.gz
MFC r274898:
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 Differential Revision: https://reviews.freebsd.org/D1197
Diffstat (limited to 'usr.sbin/rtadvd')
-rw-r--r--usr.sbin/rtadvd/rtadvd.c10
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:"
OpenPOWER on IntegriCloud