Page MenuHomeFreeBSD

Fix clang 3.5.0 warning in usr.bin/locate
ClosedPublic

Authored by dim on Nov 19 2014, 9:13 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 27, 8:35 AM
Unknown Object (File)
Nov 21 2024, 11:37 PM
Unknown Object (File)
Nov 8 2024, 4:41 PM
Unknown Object (File)
Nov 5 2024, 2:07 AM
Unknown Object (File)
Oct 29 2024, 11:31 AM
Unknown Object (File)
Oct 27 2024, 4:17 AM
Unknown Object (File)
Oct 27 2024, 4:17 AM
Unknown Object (File)
Oct 27 2024, 4:16 AM
Subscribers
None

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 - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

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.

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?

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 edited edge metadata.
This revision is now accepted and ready to land.Nov 19 2014, 10:56 PM
dim updated this revision to Diff 2508.

Closed by commit rS274847 (authored by @dim).