Page MenuHomeFreeBSD

Fix clang 3.5.0 warnings in usr.sbin/rtadvd
ClosedPublic

Authored by dim on Nov 19 2014, 9:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 7, 6:39 PM
Unknown Object (File)
Sun, Nov 3, 10:11 PM
Unknown Object (File)
Sun, Nov 3, 10:41 AM
Unknown Object (File)
Thu, Oct 31, 2:44 PM
Unknown Object (File)
Sep 24 2024, 9:55 PM
Unknown Object (File)
Sep 16 2024, 10:00 AM
Unknown Object (File)
Sep 11 2024, 1:32 PM
Unknown Object (File)
Sep 10 2024, 12:26 PM
Subscribers
None

Details

Summary

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->pfx_pltimeexpire are uint32_t's, so the subtraction expression is
also unsigned, and calling abs() is a no-op.

However, the intention was probably 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.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

dim retitled this revision from to Fix clang 3.5.0 warnings in usr.sbin/rtadvd.
dim updated this object.
dim edited the test plan for this revision. (Show Details)
dim added reviewers: hrs, emaste, theraven.
hrs edited edge metadata.

Yes, the intention of this code was to obtain absolute value of the difference as you pointed out. I think the patch is good.

This revision is now accepted and ready to land.Nov 22 2014, 10:42 PM
dim updated this revision to Diff 2512.

Closed by commit rS274898 (authored by @dim).