diff options
author | ngie <ngie@FreeBSD.org> | 2015-10-25 07:42:56 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2015-10-25 07:42:56 +0000 |
commit | 5ed05b2c9b555cf97cf76324a71ee14b23f6366a (patch) | |
tree | 997ee5278f3bc5b7400cdd44870dc0dec469a36b /lib/libc | |
parent | 6cbc0a272572035a0c0c63932c466c648eb0ea5b (diff) | |
download | FreeBSD-src-5ed05b2c9b555cf97cf76324a71ee14b23f6366a.zip FreeBSD-src-5ed05b2c9b555cf97cf76324a71ee14b23f6366a.tar.gz |
Fix compiling with gcc [4.2.1] after r287797 when MK_HESOID == no and
MK_NIS == no by converting `i` back to an int, and instead cast the loop
comparison to `int`
The loop comparison is iterating the len(ns_dtab)-1, because
the last element is the sentinel tuple { NULL, NULL, NULL, }, so when
both HESOID and NIS are off, len(ns_dtab)-1 == 1 - 1 == 0, and the loop
is skipped because the expression is tautologically false
While here, convert `(sizeof(x) / sizeof(x[0]))` to `nitems(x)`
Tested with: clang 3.7.0, gcc 4.2.1, and gcc 4.9.4 [*] with MK_NIS={no,yes}
and by running bash -lc 'id -u && id -g && id'
* gcc 4.9.4 needs another patch in order for the compile to succeed
with -Werror with lib/libc/gen/getgrent.c
Reported by: jhibbits
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/getgrent.c | 12 | ||||
-rw-r--r-- | lib/libc/gen/getpwent.c | 10 |
2 files changed, 9 insertions, 13 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 31d2af1..0e18bbb 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -1239,14 +1239,13 @@ compat_setgrent(void *retval, void *mdata, va_list ap) int rv, stayopen; #define set_setent(x, y) do { \ - unsigned int i; \ - \ - for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + int i; \ + for (i = 0; i < (int)(nitems(x) - 1); i++) \ x[i].mdata = (void *)y; \ } while (0) rv = compat_getstate(&st); - if (rv != 0) + if (rv != 0) return (NS_UNAVAIL); switch ((enum constants)mdata) { case SETGRENT: @@ -1309,9 +1308,8 @@ compat_group(void *retval, void *mdata, va_list ap) int rv, stayopen, *errnop; #define set_lookup_type(x, y) do { \ - unsigned int i; \ - \ - for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + int i; \ + for (i = 0; i < (int)(nitems(x) - 1); i++) \ x[i].mdata = (void *)y; \ } while (0) diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 6546f587..8617ecc 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1607,10 +1607,9 @@ compat_redispatch(struct compat_state *st, enum nss_lookup_type how, { NULL, NULL, NULL } }; void *discard; - int rv, e; - unsigned int i; + int e, i, rv; - for (i = 0; i < sizeof(dtab)/sizeof(dtab[0]) - 1; i++) + for (i = 0; i < (int)(nitems(dtab) - 1); i++) dtab[i].mdata = (void *)lookup_how; more: pwd_init(pwd); @@ -1703,9 +1702,8 @@ compat_setpwent(void *retval, void *mdata, va_list ap) int rv, stayopen; #define set_setent(x, y) do { \ - unsigned int i; \ - \ - for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + int i; \ + for (i = 0; i < (int)(nitems(x) - 1); i++) \ x[i].mdata = (void *)y; \ } while (0) |