summaryrefslogtreecommitdiffstats
path: root/usr.bin/locate
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2014-11-22 12:13:05 +0000
committerdim <dim@FreeBSD.org>2014-11-22 12:13:05 +0000
commit797f27009cf846619828983728ea6d646af3770f (patch)
tree33694f5b21e6698d44ddf6c51f8ab851df094f46 /usr.bin/locate
parentf3c5cded787fe5809335d5009e4e2012d3e3829b (diff)
downloadFreeBSD-src-797f27009cf846619828983728ea6d646af3770f.zip
FreeBSD-src-797f27009cf846619828983728ea6d646af3770f.tar.gz
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 MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D1196
Diffstat (limited to 'usr.bin/locate')
-rw-r--r--usr.bin/locate/locate/util.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c
index a28690a..3ac69b5 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);
}
OpenPOWER on IntegriCloud