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
This commit is contained in:
parent
fdaadf20c4
commit
0c4bf57982
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user