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
This commit is contained in:
parent
c3e5ebe1fc
commit
f28c40aee0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=274898
@ -1230,6 +1230,12 @@ ra_input(int len, struct nd_router_advert *nra,
|
|||||||
return;
|
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 */
|
/* return a non-zero value if the received prefix is inconsitent with ours */
|
||||||
static int
|
static int
|
||||||
prefix_check(struct nd_opt_prefix_info *pinfo,
|
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;
|
preferred_time += now.tv_sec;
|
||||||
|
|
||||||
if (!pfx->pfx_timer && rai->rai_clockskew &&
|
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,
|
syslog(LOG_INFO,
|
||||||
"<%s> preferred lifetime for %s/%d"
|
"<%s> preferred lifetime for %s/%d"
|
||||||
" (decr. in real time) inconsistent on %s:"
|
" (decr. in real time) inconsistent on %s:"
|
||||||
@ -1321,7 +1327,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
|
|||||||
valid_time += now.tv_sec;
|
valid_time += now.tv_sec;
|
||||||
|
|
||||||
if (!pfx->pfx_timer && rai->rai_clockskew &&
|
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,
|
syslog(LOG_INFO,
|
||||||
"<%s> valid lifetime for %s/%d"
|
"<%s> valid lifetime for %s/%d"
|
||||||
" (decr. in real time) inconsistent on %s:"
|
" (decr. in real time) inconsistent on %s:"
|
||||||
|
Loading…
Reference in New Issue
Block a user