Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Nov 2014 23:04:33 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r274898 - head/usr.sbin/rtadvd
Message-ID:  <201411222304.sAMN4X2b058291@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Sat Nov 22 23:04:33 2014
New Revision: 274898
URL: https://svnweb.freebsd.org/changeset/base/274898

Log:
  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

Modified:
  head/usr.sbin/rtadvd/rtadvd.c

Modified: head/usr.sbin/rtadvd/rtadvd.c
==============================================================================
--- head/usr.sbin/rtadvd/rtadvd.c	Sat Nov 22 22:13:00 2014	(r274897)
+++ head/usr.sbin/rtadvd/rtadvd.c	Sat Nov 22 23:04:33 2014	(r274898)
@@ -1230,6 +1230,12 @@ ra_input(int len, struct nd_router_adver
 	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 *
 		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 *
 		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:"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201411222304.sAMN4X2b058291>