From b1befc77f6b76dfd49a66de04060c4a37e759160 Mon Sep 17 00:00:00 2001 From: dim Date: Tue, 25 Nov 2014 12:45:31 +0000 Subject: [PATCH] MFC r274847: 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 store it into an integer, and don't call ntohl() again. Reviewed by: ngie Differential Revision: https://reviews.freebsd.org/D1196 git-svn-id: svn://svn.freebsd.org/base/stable/8@275034 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/locate/locate/util.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c index 9cd02b00d..44d9fb80b 100644 --- a/usr.bin/locate/locate/util.c +++ b/usr.bin/locate/locate/util.c @@ -235,7 +235,7 @@ getwm(p) char buf[INTSIZE]; int i; } u; - register int i; + register int i, hi; for (i = 0; i < (int)INTSIZE; i++) u.buf[i] = *p++; @@ -243,10 +243,11 @@ getwm(p) i = u.i; if (i > MAXPATHLEN || i < -(MAXPATHLEN)) { - i = ntohl(i); - if (i > MAXPATHLEN || i < -(MAXPATHLEN)) + hi = ntohl(i); + if (hi > MAXPATHLEN || hi < -(MAXPATHLEN)) errx(1, "integer out of +-MAXPATHLEN (%d): %u", - MAXPATHLEN, abs(i) < abs(htonl(i)) ? i : htonl(i)); + MAXPATHLEN, abs(i) < abs(hi) ? i : hi); + return(hi); } return(i); } @@ -263,16 +264,16 @@ int getwf(fp) FILE *fp; { - register int word; + register int word, hword; word = getw(fp); if (word > MAXPATHLEN || word < -(MAXPATHLEN)) { - word = ntohl(word); - if (word > MAXPATHLEN || word < -(MAXPATHLEN)) + hword = ntohl(word); + if (hword > MAXPATHLEN || hword < -(MAXPATHLEN)) errx(1, "integer out of +-MAXPATHLEN (%d): %u", - MAXPATHLEN, abs(word) < abs(htonl(word)) ? word : - htonl(word)); + MAXPATHLEN, abs(word) < abs(hword) ? word : hword); + return(hword); } return(word); } -- 2.45.0