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)
Feb 22 2024, 9:30 AM
Unknown Object (File)
Feb 10 2024, 9:33 PM
Unknown Object (File)
Feb 2 2024, 10:44 PM
Unknown Object (File)
Jan 19 2024, 5:45 PM
Unknown Object (File)
Dec 23 2023, 10:32 AM
Unknown Object (File)
Dec 16 2023, 8:50 AM
Unknown Object (File)
Dec 16 2023, 8:49 AM
Unknown Object (File)
Dec 16 2023, 5:28 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).