Page MenuHomeFreeBSD

Fix clang 3.5.0 warning in usr.bin/locate
ClosedPublic

Authored by dim on Nov 19 2014, 9:13 PM.

Details

Summary

Fix the following -Werror warnings from clang 3.5.0, while building
usr.bin/locate:

usr.bin/locate/locate/util.c:249:29: error: taking the absolute value of unsigned type 'unsigned int' has no effect [-Werror,-Wabsolute-value]
                            MAXPATHLEN, abs(i) < abs(htonl(i)) ? i : htonl(i));
                                                 ^
usr.bin/locate/locate/util.c:249:29: note: remove the call to 'abs' since unsigned values cannot be negative
                            MAXPATHLEN, abs(i) < abs(htonl(i)) ? i : htonl(i));
                                                 ^~~
usr.bin/locate/locate/util.c:274:32: error: taking the absolute value of unsigned type 'unsigned int' has no effect [-Werror,-Wabsolute-value]
                            MAXPATHLEN, abs(word) < abs(htonl(word)) ? word :
                                                    ^
usr.bin/locate/locate/util.c:274:32: note: remove the call to 'abs' since unsigned values cannot be negative
                            MAXPATHLEN, abs(word) < abs(htonl(word)) ? word :
                                                    ^~~

The problem is that ntohl() always returns an unsigned quantity. In
this case, it's expected to be cast back to a signed integer, but to
stop complaints about abs() we just also store it into an integer, and
not call ntohl() again.

Diff Detail

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

Event Timeline

dim updated this revision to Diff 2468.Nov 19 2014, 9:13 PM
dim retitled this revision from to Fix clang 3.5.0 warning in usr.bin/locate.
dim updated this object.
dim edited the test plan for this revision. (Show Details)
dim added reviewers: eadler, emaste, wblock, ngie.
ngie edited edge metadata.Nov 19 2014, 10:20 PM

I'm not sure if it makes much sense to break things at this point, but would it be smarter to just store the locate database in one endian format instead of the native format?

dim added a comment.Nov 19 2014, 10:47 PM

Well, I'm not intending to rewrite locate. :) I just want the simplest fix possible for now.

Alternatively, we could shut up the warning, but it actually makes sense in this case.

ngie accepted this revision.Nov 19 2014, 10:56 PM
ngie edited edge metadata.
This revision is now accepted and ready to land.Nov 19 2014, 10:56 PM
dim closed this revision.Nov 22 2014, 12:13 PM
dim updated this revision to Diff 2508.

Closed by commit rS274847 (authored by @dim).