? fixit ? o ? gen/o ? stdio/o Index: Makefile.inc =================================================================== RCS file: /cvsroot/src/lib/libc/Makefile.inc,v retrieving revision 1.8 diff -u -p -u -r1.8 Makefile.inc --- Makefile.inc 20 Jan 2012 16:31:29 -0000 1.8 +++ Makefile.inc 11 Mar 2012 15:11:19 -0000 @@ -24,7 +24,7 @@ USE_SHLIBDIR= yes .include <bsd.own.mk> WARNS=4 -CPPFLAGS+= -D_LIBC -DLIBC_SCCS -DSYSLIBC_SCCS -D_REENTRANT +CPPFLAGS+= -D_LIBC -DLIBC_SCCS -DSYSLIBC_SCCS -D_REENTRANT -D_DIAGNOSTIC .if (${USE_HESIOD} != "no") CPPFLAGS+= -DHESIOD @@ -40,10 +40,8 @@ CPPFLAGS+= -DNLS CPPFLAGS+= -DYP .endif -.if ${MACHINE_ARCH} == "i386" # Set lint to exit on warnings LINTFLAGS+= -w -.endif # ignore 'empty translation unit' warnings. LINTFLAGS+= -X 272 Index: cdb/cdbw.c =================================================================== RCS file: /cvsroot/src/lib/libc/cdb/cdbw.c,v retrieving revision 1.1 diff -u -p -u -r1.1 cdbw.c --- cdb/cdbw.c 25 Apr 2010 00:54:46 -0000 1.1 +++ cdb/cdbw.c 11 Mar 2012 15:11:20 -0000 @@ -42,6 +42,7 @@ __RCSID("$NetBSD: cdbw.c,v 1.1 2010/04/2 #include <sys/endian.h> #include <sys/queue.h> +#include <assert.h> #include <cdbw.h> #include <stdlib.h> #include <string.h> @@ -167,7 +168,8 @@ cdbw_put_data(struct cdbw *cdbw, const v memcpy(cdbw->data_ptr[cdbw->data_counter], data, datalen); cdbw->data_len[cdbw->data_counter] = datalen; cdbw->data_size += datalen; - *idx = cdbw->data_counter++; + _DIAGASSERT(__type_fit(uint32_t, cdbw->data_counter)); + *idx = (uint32_t)cdbw->data_counter++; return 0; } @@ -330,7 +332,9 @@ remove_vertex(struct state *state, struc return; } - state->output_order[--state->output_index] = e - state->edges; + ptrdiff_t td = e - state->edges; + _DIAGASSERT(__type_fit(uint32_t, td)); + state->output_order[--state->output_index] = (uint32_t)td; vl = &state->verts[e->left]; vm = &state->verts[e->middle]; @@ -365,8 +369,7 @@ build_graph(struct cdbw *cdbw, struct st struct key_hash *key_hash; struct vertex *v; struct edge *e; - uint32_t hashes[3]; - size_t i; + uint32_t hashes[3], i; e = state->edges; for (i = 0; i < cdbw->hash_size; ++i) { @@ -492,8 +495,10 @@ print_hash(struct cdbw *cdbw, struct sta memcpy(buf, "NBCDB\n\0", 7); buf[7] = 1; strncpy((char *)buf + 8, descr, 16); - le32enc(buf + 24, cdbw->data_size); - le32enc(buf + 28, cdbw->data_counter); + _DIAGASSERT(__type_fit(uint32_t, cdbw->data_size)); + le32enc(buf + 24, (uint32_t)cdbw->data_size); + _DIAGASSERT(__type_fit(uint32_t, cdbw->data_counter)); + le32enc(buf + 28, (uint32_t)cdbw->data_counter); le32enc(buf + 32, state->entries); le32enc(buf + 36, state->seed); cur_pos = 40; @@ -504,7 +509,8 @@ print_hash(struct cdbw *cdbw, struct sta le32enc(buf + cur_pos, state->g[i]); cur_pos += size; } - size2 = compute_size(cdbw->data_size); + _DIAGASSERT(__type_fit(uint32_t, cdbw->data_counter)); + size2 = compute_size((uint32_t)cdbw->data_size); size = size * state->entries % size2; if (size != 0) { size = size2 - size; @@ -516,7 +522,9 @@ print_hash(struct cdbw *cdbw, struct sta COND_FLUSH_BUFFER(4); le32enc(buf + cur_pos, data_size); cur_pos += size2; - data_size += cdbw->data_len[i]; + _DIAGASSERT(__type_fit(uint32_t, + data_size + cdbw->data_len[i])); + data_size += (uint32_t)cdbw->data_len[i]; } COND_FLUSH_BUFFER(4); le32enc(buf + cur_pos, data_size); @@ -561,8 +569,10 @@ cdbw_output(struct cdbw *cdbw, int fd, c rv = 0; - state.keys = cdbw->key_counter; - state.data_entries = cdbw->data_counter; + _DIAGASSERT(__type_fit(uint32_t, cdbw->key_counter)); + state.keys = (uint32_t)cdbw->key_counter; + _DIAGASSERT(__type_fit(uint32_t, cdbw->key_counter)); + state.data_entries = (uint32_t)cdbw->data_counter; state.entries = state.keys + (state.keys + 3) / 4; if (state.entries < 10) state.entries = 10; Index: citrus/citrus_memstream.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/citrus_memstream.c,v retrieving revision 1.4 diff -u -p -u -r1.4 citrus_memstream.c --- citrus/citrus_memstream.c 3 Feb 2009 05:02:12 -0000 1.4 +++ citrus/citrus_memstream.c 11 Mar 2012 15:11:20 -0000 @@ -46,7 +46,7 @@ const char * _citrus_memory_stream_getln(struct _citrus_memory_stream * __restrict ms, size_t * __restrict rlen) { - int i; + size_t i; const uint8_t *h, *p; size_t ret; Index: compat/db/hash/compat_ndbmdatum.c =================================================================== RCS file: /cvsroot/src/lib/libc/compat/db/hash/compat_ndbmdatum.c,v retrieving revision 1.1 diff -u -p -u -r1.1 compat_ndbmdatum.c --- compat/db/hash/compat_ndbmdatum.c 13 Sep 2005 01:44:09 -0000 1.1 +++ compat/db/hash/compat_ndbmdatum.c 11 Mar 2012 15:11:21 -0000 @@ -28,4 +28,6 @@ __warn_references(dbm_store, " include <ndbm.h> for correct reference") #define datum datum12 +#define datum_truncate(a) ((a) > INT_MAX ? INT_MAX : (int)(a)) + #include "db/hash/ndbmdatum.c" Index: compat/gen/compat___fts13.c =================================================================== RCS file: /cvsroot/src/lib/libc/compat/gen/compat___fts13.c,v retrieving revision 1.6 diff -u -p -u -r1.6 compat___fts13.c --- compat/gen/compat___fts13.c 19 Oct 2009 17:52:01 -0000 1.6 +++ compat/gen/compat___fts13.c 11 Mar 2012 15:11:21 -0000 @@ -33,6 +33,11 @@ __warn_references(__fts_set13, #define __fts_dev_t uint32_t #define __fts_level_t short +#ifndef fts_namelen_truncate +#define fts_namelen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif + #define stat __stat13 #define lstat __lstat13 #define fstat __fstat13 Index: compat/gen/compat___fts30.c =================================================================== RCS file: /cvsroot/src/lib/libc/compat/gen/compat___fts30.c,v retrieving revision 1.3 diff -u -p -u -r1.3 compat___fts30.c --- compat/gen/compat___fts30.c 19 Oct 2009 17:52:04 -0000 1.3 +++ compat/gen/compat___fts30.c 11 Mar 2012 15:11:21 -0000 @@ -36,6 +36,11 @@ __warn_references(__fts_set30, #define lstat __lstat30 #define fstat __fstat30 +#ifndef fts_namelen_truncate +#define fts_namelen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif + #undef fts_children #define fts_children __fts_children30 #undef fts_close Index: compat/gen/compat___fts31.c =================================================================== RCS file: /cvsroot/src/lib/libc/compat/gen/compat___fts31.c,v retrieving revision 1.2 diff -u -p -u -r1.2 compat___fts31.c --- compat/gen/compat___fts31.c 19 Oct 2009 17:52:05 -0000 1.2 +++ compat/gen/compat___fts31.c 11 Mar 2012 15:11:21 -0000 @@ -31,6 +31,11 @@ __warn_references(__fts_set31, #define __fts_dev_t uint32_t #define __fts_level_t short +#ifndef fts_namelen_truncate +#define fts_namelen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif + #define stat __stat30 #define lstat __lstat30 #define fstat __fstat30 Index: compat/sys/compat_getdents.c =================================================================== RCS file: /cvsroot/src/lib/libc/compat/sys/compat_getdents.c,v retrieving revision 1.4 diff -u -p -u -r1.4 compat_getdents.c --- compat/sys/compat_getdents.c 20 Jun 2011 09:11:17 -0000 1.4 +++ compat/sys/compat_getdents.c 11 Mar 2012 15:11:21 -0000 @@ -52,6 +52,7 @@ getdents(int fd, char *buf, size_t nbyte struct dirent12 *odp; ino_t ino; int rv; + size_t len; if ((rv = __getdents30(fd, buf, nbytes)) == -1) return rv; @@ -78,8 +79,12 @@ getdents(int fd, char *buf, size_t nbyte odp->d_type = ndp->d_type; (void)memcpy(odp->d_name, ndp->d_name, (size_t)odp->d_namlen); odp->d_name[odp->d_namlen] = '\0'; - odp->d_reclen = _DIRENT_SIZE(odp); + len = _DIRENT_SIZE(odp); + _DIAGASSERT(__type_fit(uint16_t, len)); + odp->d_reclen = (uint16_t)len; odp = _DIRENT_NEXT(odp); } - return ((char *)(void *)odp) - buf; + ptrdiff_t td = (((char *)(void *)odp) - buf); + _DIAGASSERT(__type_fit(int, td)); + return (int)td; } Index: compat/sys/compat_sigaltstack.c =================================================================== RCS file: /cvsroot/src/lib/libc/compat/sys/compat_sigaltstack.c,v retrieving revision 1.3 diff -u -p -u -r1.3 compat_sigaltstack.c --- compat/sys/compat_sigaltstack.c 11 Jan 2009 02:46:26 -0000 1.3 +++ compat/sys/compat_sigaltstack.c 11 Mar 2012 15:11:21 -0000 @@ -62,7 +62,7 @@ sigaltstack(onss, ooss) if (oss.ss_size > INT_MAX) ooss->ss_size = INT_MAX; else - ooss->ss_size = oss.ss_size; + ooss->ss_size = (int)oss.ss_size; ooss->ss_flags = oss.ss_flags; } Index: db/btree/bt_open.c =================================================================== RCS file: /cvsroot/src/lib/libc/db/btree/bt_open.c,v retrieving revision 1.25 diff -u -p -u -r1.25 bt_open.c --- db/btree/bt_open.c 17 Apr 2011 23:12:38 -0000 1.25 +++ db/btree/bt_open.c 11 Mar 2012 15:11:21 -0000 @@ -304,9 +304,11 @@ __bt_open(const char *fname, int flags, (sizeof(indx_t) + NBLEAFDBT(0, 0)); _DBFIT(temp, indx_t); t->bt_ovflsize = (indx_t)temp; - if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t)) - t->bt_ovflsize = - NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t); + if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t)) { + size_t l = NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t); + _DBFIT(l, indx_t); + t->bt_ovflsize = (indx_t)l; + } /* Initialize the buffer pool. */ if ((t->bt_mp = Index: db/btree/bt_overflow.c =================================================================== RCS file: /cvsroot/src/lib/libc/db/btree/bt_overflow.c,v retrieving revision 1.17 diff -u -p -u -r1.17 bt_overflow.c --- db/btree/bt_overflow.c 26 Jun 2011 22:20:31 -0000 1.17 +++ db/btree/bt_overflow.c 11 Mar 2012 15:11:21 -0000 @@ -155,7 +155,7 @@ __ovfl_put(BTREE *t, const DBT *dbt, pgn p = dbt->data; temp = dbt->size; _DBFIT(temp, uint32_t); - sz = temp; + sz = (uint32_t)temp; for (;; p = (char *)p + plen, last = h) { if ((h = __bt_new(t, &npg)) == NULL) return (RET_ERROR); Index: db/hash/hash.c =================================================================== RCS file: /cvsroot/src/lib/libc/db/hash/hash.c,v retrieving revision 1.31 diff -u -p -u -r1.31 hash.c --- db/hash/hash.c 12 Feb 2009 06:35:54 -0000 1.31 +++ db/hash/hash.c 11 Mar 2012 15:11:21 -0000 @@ -212,7 +212,7 @@ __hash_open(const char *file, int flags, dbp->sync = hash_sync; dbp->type = DB_HASH; -#ifdef DEBUG +#ifdef DEBUG1 (void)fprintf(stderr, "%s\n%s%p\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n", "init_htab:", @@ -813,7 +813,9 @@ __expand_table(HTAB *hashp) dirsize = hashp->DSIZE * sizeof(SEGMENT *); if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1)) return (-1); - hashp->DSIZE = dirsize << 1; + dirsize <<= 1; + _DBFIT(dirsize, uint32_t); + hashp->DSIZE = (uint32_t)dirsize; } if ((hashp->dir[new_segnum] = calloc((size_t)hashp->SGSIZE, sizeof(SEGMENT))) == NULL) Index: db/hash/hash_bigkey.c =================================================================== RCS file: /cvsroot/src/lib/libc/db/hash/hash_bigkey.c,v retrieving revision 1.23 diff -u -p -u -r1.23 hash_bigkey.c --- db/hash/hash_bigkey.c 12 Feb 2009 06:33:13 -0000 1.23 +++ db/hash/hash_bigkey.c 11 Mar 2012 15:11:22 -0000 @@ -107,7 +107,9 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, _DBFIT(temp, uint16_t); space = (uint16_t)temp; while (key_size) { - move_bytes = MIN(space, key_size); + size_t kspace = MIN(space, key_size); + _DBFIT(kspace, uint16_t); + move_bytes = (uint16_t)kspace; off = OFFSET(p) - move_bytes; memmove(cp + off, key_data, (size_t)move_bytes); key_size -= move_bytes; @@ -127,7 +129,9 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, if (!key_size) { space = FREESPACE(p); if (space) { - move_bytes = MIN(space, val_size); + size_t vspace = MIN(space, val_size); + _DBFIT(vspace, uint16_t); + move_bytes = (uint16_t)vspace; /* * If the data would fit exactly in the * remaining space, we must overflow it to the @@ -163,7 +167,9 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, _DBFIT(temp, uint16_t); space = (uint16_t)temp; while (val_size) { - move_bytes = MIN(space, val_size); + size_t vspace = MIN(space, val_size); + _DBFIT(vspace, uint16_t); + move_bytes = (uint16_t)vspace; /* * Here's the hack to make sure that if the data ends on the * same page as the key ends, FREESPACE is at least one. Index: db/hash/hash_page.c =================================================================== RCS file: /cvsroot/src/lib/libc/db/hash/hash_page.c,v retrieving revision 1.24 diff -u -p -u -r1.24 hash_page.c --- db/hash/hash_page.c 17 Apr 2011 23:12:38 -0000 1.24 +++ db/hash/hash_page.c 11 Mar 2012 15:11:23 -0000 @@ -85,7 +85,7 @@ static int ugly_split(HTAB *, uint32_t, #define PAGE_INIT(P) { \ ((uint16_t *)(void *)(P))[0] = 0; \ temp = 3 * sizeof(uint16_t); \ - _DIAGASSERT(hashp->BSIZE >= temp); \ + _DIAGASSERT((size_t)hashp->BSIZE >= temp); \ ((uint16_t *)(void *)(P))[1] = (uint16_t)(hashp->BSIZE - temp); \ ((uint16_t *)(void *)(P))[2] = hashp->BSIZE; \ } Index: db/hash/ndbmdatum.c =================================================================== RCS file: /cvsroot/src/lib/libc/db/hash/ndbmdatum.c,v retrieving revision 1.4 diff -u -p -u -r1.4 ndbmdatum.c --- db/hash/ndbmdatum.c 11 Sep 2008 12:58:00 -0000 1.4 +++ db/hash/ndbmdatum.c 11 Mar 2012 15:11:23 -0000 @@ -54,6 +54,9 @@ __RCSID("$NetBSD: ndbmdatum.c,v 1.4 2008 #include <ndbm.h> #include "hash.h" +#ifndef datum_truncate +#define datum_truncate(a) (a) +#endif /* * Returns: * DATUM on success @@ -74,7 +77,7 @@ dbm_fetch(DBM *db, datum key) dbtretdata.size = 0; } retdata.dptr = dbtretdata.data; - retdata.dsize = dbtretdata.size; + retdata.dsize = datum_truncate(dbtretdata.size); return (retdata); } @@ -94,7 +97,7 @@ dbm_firstkey(DBM *db) if (status) dbtretkey.data = NULL; retkey.dptr = dbtretkey.data; - retkey.dsize = dbtretkey.size; + retkey.dsize = datum_truncate(dbtretkey.size); return (retkey); } @@ -114,7 +117,7 @@ dbm_nextkey(DBM *db) if (status) dbtretkey.data = NULL; retkey.dptr = dbtretkey.data; - retkey.dsize = dbtretkey.size; + retkey.dsize = datum_truncate(dbtretkey.size); return (retkey); } Index: dlfcn/dlfcn_elf.c =================================================================== RCS file: /cvsroot/src/lib/libc/dlfcn/dlfcn_elf.c,v retrieving revision 1.11 diff -u -p -u -r1.11 dlfcn_elf.c --- dlfcn/dlfcn_elf.c 16 Feb 2012 23:00:39 -0000 1.11 +++ dlfcn/dlfcn_elf.c 11 Mar 2012 15:11:23 -0000 @@ -32,6 +32,7 @@ __RCSID("$NetBSD: dlfcn_elf.c,v 1.11 201 #include "namespace.h" #include <sys/atomic.h> +#include <assert.h> #include <elf.h> #include <errno.h> #include <string.h> @@ -165,7 +166,8 @@ dl_iterate_phdr_setup(void) dlpi_phdr = (void *)aux->a_v; break; case AT_PHNUM: - dlpi_phnum = aux->a_v; + _DIAGASSERT(__type_fit(Elf_Half, aux->a_v)); + dlpi_phnum = (Elf_Half)aux->a_v; break; case AT_SUN_EXECNAME: dlpi_name = (void *)aux->a_v; Index: gdtoa/gdtoa.c =================================================================== RCS file: /cvsroot/src/lib/libc/gdtoa/gdtoa.c,v retrieving revision 1.5 diff -u -p -u -r1.5 gdtoa.c --- gdtoa/gdtoa.c 20 Mar 2011 23:15:35 -0000 1.5 +++ gdtoa/gdtoa.c 11 Mar 2012 15:11:23 -0000 @@ -65,7 +65,9 @@ bitstob(ULong *bits, int nbits, int *bbi *x++ = (*bits >> 16) & ALL_ON; #endif } while(++bits <= be); - i = x - x0; + ptrdiff_t td = x - x0; + _DIAGASSERT(__type_fit(int, td)); + i = (int)td; while(!x0[--i]) if (!i) { b->wds = 0; Index: gdtoa/gdtoaimp.h =================================================================== RCS file: /cvsroot/src/lib/libc/gdtoa/gdtoaimp.h,v retrieving revision 1.12 diff -u -p -u -r1.12 gdtoaimp.h --- gdtoa/gdtoaimp.h 4 Jun 2011 14:18:10 -0000 1.12 +++ gdtoa/gdtoaimp.h 11 Mar 2012 15:11:24 -0000 @@ -179,6 +179,7 @@ THIS SOFTWARE. /* #define IEEE_{BIG,LITTLE}_ENDIAN in ${ARCHDIR}/gdtoa/arith.h */ +#include <assert.h> #include <stdint.h> #define Short int16_t #define UShort uint16_t @@ -617,7 +618,7 @@ extern void memcpy_D2A ANSI((void*, cons extern double ratio ANSI((Bigint*, Bigint*)); extern void rshift ANSI((Bigint*, int)); extern char *rv_alloc ANSI((size_t)); - extern Bigint *s2b ANSI((CONST char*, int, int, ULong, int)); + extern Bigint *s2b ANSI((CONST char*, int, int, ULong, size_t)); extern Bigint *set_ones ANSI((Bigint*, int)); extern char *strcp ANSI((char*, const char*)); extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*)); Index: gdtoa/gmisc.c =================================================================== RCS file: /cvsroot/src/lib/libc/gdtoa/gmisc.c,v retrieving revision 1.3 diff -u -p -u -r1.3 gmisc.c --- gdtoa/gmisc.c 11 Mar 2006 18:38:14 -0000 1.3 +++ gdtoa/gmisc.c 11 Mar 2012 15:11:24 -0000 @@ -62,7 +62,10 @@ rshift(Bigint *b, int k) while(x < xe) *x1++ = *x++; } - if ((b->wds = x1 - b->x) == 0) + + ptrdiff_t td = x1 - b->x; + _DIAGASSERT(__type_fit(int, td)); + if ((b->wds = (int)td) == 0) b->x[0] = 0; } Index: gdtoa/smisc.c =================================================================== RCS file: /cvsroot/src/lib/libc/gdtoa/smisc.c,v retrieving revision 1.4 diff -u -p -u -r1.4 smisc.c --- gdtoa/smisc.c 20 Mar 2011 23:15:35 -0000 1.4 +++ gdtoa/smisc.c 11 Mar 2012 15:11:24 -0000 @@ -38,7 +38,7 @@ s2b #ifdef KR_headers (s, nd0, nd, y9, dplen) CONST char *s; int dplen, nd0, nd; ULong y9; #else - (CONST char *s, int nd0, int nd, ULong y9, int dplen) + (CONST char *s, int nd0, int nd, ULong y9, size_t dplen) #endif { Bigint *b; Index: gdtoa/strtod.c =================================================================== RCS file: /cvsroot/src/lib/libc/gdtoa/strtod.c,v retrieving revision 1.8 diff -u -p -u -r1.8 strtod.c --- gdtoa/strtod.c 27 Mar 2011 11:21:54 -0000 1.8 +++ gdtoa/strtod.c 11 Mar 2012 15:11:24 -0000 @@ -119,7 +119,7 @@ strtod #else char *decimalpoint; static char *decimalpoint_cache; - static int dplen; + static size_t dplen; if (!(s0 = decimalpoint_cache)) { s0 = localeconv()->decimal_point; if ((decimalpoint_cache = MALLOC(strlen(s0) + 1)) != NULL) { Index: gdtoa/strtodg.c =================================================================== RCS file: /cvsroot/src/lib/libc/gdtoa/strtodg.c,v retrieving revision 1.8 diff -u -p -u -r1.8 strtodg.c --- gdtoa/strtodg.c 21 Mar 2011 12:53:50 -0000 1.8 +++ gdtoa/strtodg.c 11 Mar 2012 15:11:25 -0000 @@ -346,7 +346,7 @@ strtodg #else char *decimalpoint; static char *decimalpoint_cache; - static int dplen; + static size_t dplen; if (!(s0 = decimalpoint_cache)) { s0 = localeconv()->decimal_point; if ((decimalpoint_cache = MALLOC(strlen(s0) + 1)) != NULL) { Index: gen/dehumanize_number.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/dehumanize_number.c,v retrieving revision 1.3 diff -u -p -u -r1.3 dehumanize_number.c --- gen/dehumanize_number.c 28 Apr 2008 20:22:59 -0000 1.3 +++ gen/dehumanize_number.c 11 Mar 2012 15:11:25 -0000 @@ -35,6 +35,7 @@ __RCSID("$NetBSD: dehumanize_number.c,v #endif /* LIBC_SCCS and not lint */ #include "namespace.h" +#include <assert.h> #include <inttypes.h> #include <ctype.h> #include <stdlib.h> @@ -109,7 +110,9 @@ dehumanize_number(const char *str, int64 errno = ERANGE; return -1; /* Out of range. */ } - *size = tmp * multiplier; + tmp *= multiplier; + _DIAGASSERT(__type_fit(int64_t, tmp)); + *size = (int64_t)tmp; return 0; } Index: gen/disklabel.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/disklabel.c,v retrieving revision 1.34 diff -u -p -u -r1.34 disklabel.c --- gen/disklabel.c 19 Mar 2006 02:17:16 -0000 1.34 +++ gen/disklabel.c 11 Mar 2012 15:11:25 -0000 @@ -219,7 +219,7 @@ gettype(t, names) for (nm = names; *nm; nm++) if (strcasecmp(t, *nm) == 0) - return (nm - names); + return (int)(nm - names); if (isdigit((unsigned char) *t)) return (atoi(t)); return (0); Index: gen/extattr.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/extattr.c,v retrieving revision 1.3 diff -u -p -u -r1.3 extattr.c --- gen/extattr.c 3 Aug 2011 04:11:17 -0000 1.3 +++ gen/extattr.c 11 Mar 2012 15:11:25 -0000 @@ -103,7 +103,7 @@ extattr_copy_fd(int from_fd, int to_fd, size_t alen; void *alist = NULL; void *aval = NULL; - int i; + size_t i; int error = -1; llen = extattr_list_fd(from_fd, namespace, NULL, 0); @@ -130,7 +130,7 @@ extattr_copy_fd(int from_fd, int to_fd, if ((aval = malloc((size_t)maxvlen)) == NULL) goto out; - for (i = 0; i < llen; i += alen + 1) { + for (i = 0; i < (size_t)llen; i += alen + 1) { char aname[NAME_MAX + 1]; char *ap; @@ -176,7 +176,7 @@ extattr_copy_file(const char *from, cons size_t alen; void *alist = NULL; void *aval = NULL; - int i; + size_t i; int error = -1; llen = extattr_list_file(from, namespace, NULL, 0); @@ -203,7 +203,7 @@ extattr_copy_file(const char *from, cons if ((aval = malloc((size_t)maxvlen)) == NULL) goto out; - for (i = 0; i < llen; i += alen + 1) { + for (i = 0; i < (size_t)llen; i += alen + 1) { char aname[NAME_MAX + 1]; char *ap; @@ -248,7 +248,7 @@ extattr_copy_link(const char *from, cons size_t alen; void *alist = NULL; void *aval = NULL; - int i; + size_t i; int error = -1; llen = extattr_list_link(from, namespace, NULL, 0); @@ -275,7 +275,7 @@ extattr_copy_link(const char *from, cons if ((aval = malloc((size_t)maxvlen)) == NULL) goto out; - for (i = 0; i < llen; i += alen + 1) { + for (i = 0; i < (size_t)llen; i += alen + 1) { char aname[NAME_MAX + 1]; char *ap; Index: gen/fstab.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/fstab.c,v retrieving revision 1.30 diff -u -p -u -r1.30 fstab.c --- gen/fstab.c 12 Feb 2012 13:52:51 -0000 1.30 +++ gen/fstab.c 11 Mar 2012 15:11:25 -0000 @@ -96,7 +96,7 @@ fstabscan(void) (void)memset(&_fs_fstab, 0, sizeof(_fs_fstab)); for (;;) { - if (!(lp = fgets(line, sizeof(line), _fs_fp))) + if (!(lp = fgets(line, (int)sizeof(line), _fs_fp))) return 0; _fs_lineno++; /* OLD_STYLE_FSTAB */ Index: gen/fts.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/fts.c,v retrieving revision 1.42 diff -u -p -u -r1.42 fts.c --- gen/fts.c 16 Oct 2011 05:05:38 -0000 1.42 +++ gen/fts.c 11 Mar 2012 15:11:28 -0000 @@ -79,6 +79,23 @@ static int fts_safe_changedir(const FTS #undef FTS_ALLOC_ALIGNED #endif +#ifndef fts_namelen_truncate +#define fts_namelen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef fts_pathlen_truncate +#define fts_pathlen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef ftsent_pathlen_truncate +#define ftsent_pathlen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef ftsent_nitems_truncate +#define ftsent_nitems_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif + #define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) #define CLR(opt) (sp->fts_options &= ~(opt)) @@ -235,7 +252,7 @@ fts_load(FTS *sp, FTSENT *p) if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { len = strlen(++cp); memmove(p->fts_name, cp, len + 1); - p->fts_namelen = len; + p->fts_namelen = fts_namelen_truncate(len); } p->fts_accpath = p->fts_path = sp->fts_path; sp->fts_dev = p->fts_dev; @@ -790,7 +807,7 @@ mem1: saved_errno = errno; } #endif p->fts_level = level; - p->fts_pathlen = len + dnamlen; + p->fts_pathlen = ftsent_pathlen_truncate(len + dnamlen); p->fts_parent = sp->fts_cur; #ifdef FTS_WHITEOUT @@ -994,7 +1011,7 @@ fts_sort(FTS *sp, FTSENT *head, size_t n if (new == 0) return (head); sp->fts_array = new; - sp->fts_nitems = nitems + 40; + sp->fts_nitems = ftsent_nitems_truncate(nitems + 40); } for (ap = sp->fts_array, p = head; p; p = p->fts_link) *ap++ = p; @@ -1052,7 +1069,7 @@ fts_alloc(FTS *sp, const char *name, siz /* Copy the name plus the trailing NULL. */ memmove(p->fts_name, name, namelen + 1); - p->fts_namelen = namelen; + p->fts_namelen = fts_namelen_truncate(namelen); p->fts_path = sp->fts_path; p->fts_errno = 0; p->fts_flags = 0; @@ -1131,7 +1148,7 @@ fts_palloc(FTS *sp, size_t size) if (new == 0) return (1); sp->fts_path = new; - sp->fts_pathlen = size; + sp->fts_pathlen = fts_pathlen_truncate(size); return (0); } Index: gen/getcap.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/getcap.c,v retrieving revision 1.50 diff -u -p -u -r1.50 getcap.c --- gen/getcap.c 15 Oct 2011 23:00:01 -0000 1.50 +++ gen/getcap.c 11 Mar 2012 15:11:28 -0000 @@ -52,6 +52,7 @@ __RCSID("$NetBSD: getcap.c,v 1.50 2011/1 #include <sys/param.h> #include <assert.h> +#include <stddef.h> #include <ctype.h> #ifndef SMALL #include <db.h> @@ -393,7 +394,7 @@ getent(char **cap, size_t *len, const ch rp = record; for (;;) { if (bp >= b_end) { - int n; + ssize_t n; n = read(fd, buf, sizeof(buf)); if (n <= 0) { @@ -456,7 +457,7 @@ getent(char **cap, size_t *len, const ch * some more. */ if (rp >= r_end) { - u_int pos; + ptrdiff_t pos; size_t newsize; pos = rp - record; @@ -518,7 +519,8 @@ tc_exp: if (expandtc) { char *newicap, *s; size_t ilen, newilen; - int diff, iret, tclen; + int iret; + ptrdiff_t diff, tclen; char *icap, *scan, *tc, *tcstart, *tcend; /* @@ -597,7 +599,7 @@ tc_exp: */ diff = newilen - tclen; if (diff >= r_end - rp) { - u_int pos, tcpos, tcposend; + ptrdiff_t pos, tcpos, tcposend; size_t newsize; pos = rp - record; @@ -917,7 +919,7 @@ cgetstr(char *buf, const char *cap, char u_int m_room; const char *bp; char *mp; - int len; + ptrdiff_t len; char *mem, *newmem; _DIAGASSERT(buf != NULL); @@ -1033,7 +1035,8 @@ cgetstr(char *buf, const char *cap, char mem = newmem; } *str = mem; - return len; + _DIAGASSERT(__type_fit(int, len)); + return (int)len; } /* @@ -1052,7 +1055,7 @@ cgetustr(char *buf, const char *cap, cha u_int m_room; const char *bp; char *mp; - int len; + size_t len; char *mem, *newmem; _DIAGASSERT(buf != NULL); @@ -1117,7 +1120,8 @@ cgetustr(char *buf, const char *cap, cha mem = newmem; } *str = mem; - return len; + _DIAGASSERT(__type_fit(int, len)); + return (int)len; } /* Index: gen/getcwd.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/getcwd.c,v retrieving revision 1.50 diff -u -p -u -r1.50 getcwd.c --- gen/getcwd.c 21 Feb 2011 00:40:07 -0000 1.50 +++ gen/getcwd.c 11 Mar 2012 15:11:28 -0000 @@ -71,10 +71,11 @@ char * realpath(const char *path, char *resolved) { struct stat sb; - int idx = 0, n, nlnk = 0; + int idx = 0, nlnk = 0; const char *q; char *p, wbuf[2][MAXPATHLEN]; size_t len; + ssize_t n; _DIAGASSERT(resolved != NULL); Index: gen/getdevmajor.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/getdevmajor.c,v retrieving revision 1.5 diff -u -p -u -r1.5 getdevmajor.c --- gen/getdevmajor.c 20 Jan 2009 20:08:12 -0000 1.5 +++ gen/getdevmajor.c 11 Mar 2012 15:11:28 -0000 @@ -67,8 +67,8 @@ devmajor_t getdevmajor(const char *name, mode_t type) { struct kinfo_drivers kd[200], *kdp = &kd[0]; - int rc, i; - size_t sz = sizeof(kd); + size_t i, sz = sizeof(kd); + int rc; devmajor_t n = NODEVMAJOR; if (type != S_IFCHR && type != S_IFBLK) { @@ -88,9 +88,9 @@ getdevmajor(const char *name, mode_t typ } } while (rc == -1); - rc = sz / sizeof(*kdp); + sz /= sizeof(*kdp); - for (i = 0; i < rc; i++) { + for (i = 0; i < sz; i++) { if (strcmp(name, kdp[i].d_name) == 0) { if (type == S_IFCHR) n = kdp[i].d_cmajor; @@ -99,7 +99,7 @@ getdevmajor(const char *name, mode_t typ break; } } - if (i >= rc) + if (i >= sz) errno = ENOENT; out: Index: gen/getgrent.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/getgrent.c,v retrieving revision 1.64 diff -u -p -u -r1.64 getgrent.c --- gen/getgrent.c 15 Oct 2011 23:00:01 -0000 1.64 +++ gen/getgrent.c 11 Mar 2012 15:11:29 -0000 @@ -359,7 +359,7 @@ __grscan_files(int *retval, struct group rv = NS_NOTFOUND; /* scan line by line */ - while (fgets(filebuf, sizeof(filebuf), state->fp) != NULL) { + while (fgets(filebuf, (int)sizeof(filebuf), state->fp) != NULL) { ep = strchr(filebuf, '\n'); if (ep == NULL) { /* skip lines that are too big */ int ch; @@ -1427,7 +1427,7 @@ __grscan_compat(int *retval, struct grou } /* get next file line */ - if (fgets(filebuf, sizeof(filebuf), state->fp) == NULL) + if (fgets(filebuf, (int)sizeof(filebuf), state->fp) == NULL) break; ep = strchr(filebuf, '\n'); Index: gen/getloadavg.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/getloadavg.c,v retrieving revision 1.13 diff -u -p -u -r1.13 getloadavg.c --- gen/getloadavg.c 7 Aug 2003 16:42:50 -0000 1.13 +++ gen/getloadavg.c 11 Mar 2012 15:11:29 -0000 @@ -60,25 +60,22 @@ __weak_alias(getloadavg,_getloadavg) * Return number of samples retrieved, or -1 on error. */ int -getloadavg(loadavg, nelem) - double loadavg[]; - int nelem; +getloadavg(double loadavg[], int nelem) { struct loadavg loadinfo; - int i, mib[2]; - size_t size; + static const int mib[] = { CTL_VM, VM_LOADAVG }; + size_t size, i; _DIAGASSERT(loadavg != NULL); _DIAGASSERT(nelem >= 0); - mib[0] = CTL_VM; - mib[1] = VM_LOADAVG; size = sizeof(loadinfo); - if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) < 0) - return (-1); + if (sysctl(mib, (u_int)__arraycount(mib), &loadinfo, &size, NULL, 0) + == -1) + return -1; - nelem = MIN((size_t) nelem, sizeof(loadinfo.ldavg) / sizeof(fixpt_t)); - for (i = 0; i < nelem; i++) + size = MIN((size_t)nelem, __arraycount(loadinfo.ldavg)); + for (i = 0; i < size; i++) loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale; - return (nelem); + return nelem; } Index: gen/getusershell.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/getusershell.c,v retrieving revision 1.28 diff -u -p -u -r1.28 getusershell.c --- gen/getusershell.c 15 Oct 2011 23:00:01 -0000 1.28 +++ gen/getusershell.c 11 Mar 2012 15:11:29 -0000 @@ -189,7 +189,8 @@ _files_getusershell(void *nsrv, void *ns return rv; } - while (fgets(curshell, sizeof(curshell) - 1, _files_state.fp) != NULL) { + while (fgets(curshell, (int)sizeof(curshell) - 1, _files_state.fp) + != NULL) { sp = cp = curshell; while (*cp != '#' && *cp != '/' && *cp != '\0') cp++; Index: gen/humanize_number.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/humanize_number.c,v retrieving revision 1.14 diff -u -p -u -r1.14 humanize_number.c --- gen/humanize_number.c 28 Apr 2008 20:22:59 -0000 1.14 +++ gen/humanize_number.c 11 Mar 2012 15:11:29 -0000 @@ -48,9 +48,9 @@ humanize_number(char *buf, size_t len, i const char *suffix, int scale, int flags) { const char *prefixes, *sep; - int b, i, r, maxscale, s1, s2, sign; + int b, r, s1, s2, sign; int64_t divisor, max; - size_t baselen; + size_t i, baselen, maxscale; _DIAGASSERT(buf != NULL); _DIAGASSERT(suffix != NULL); @@ -78,7 +78,7 @@ humanize_number(char *buf, size_t len, i #define SCALE2PREFIX(scale) (&prefixes[(scale) << 1]) maxscale = 7; - if (scale >= maxscale && + if ((size_t)scale >= maxscale && (scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0) return (-1); @@ -121,10 +121,12 @@ humanize_number(char *buf, size_t len, i for (i = 0; bytes >= max - 50 && i < maxscale; i++) bytes /= divisor; - if (scale & HN_GETSCALE) - return (i); + if (scale & HN_GETSCALE) { + _DIAGASSERT(__type_fit(int, i)); + return (int)i; + } } else - for (i = 0; i < scale && i < maxscale; i++) + for (i = 0; i < (size_t)scale && i < maxscale; i++) bytes /= divisor; /* If a value <= 9.9 after rounding and ... */ Index: gen/initdir.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/initdir.c,v retrieving revision 1.2 diff -u -p -u -r1.2 initdir.c --- gen/initdir.c 15 Oct 2011 23:00:01 -0000 1.2 +++ gen/initdir.c 11 Mar 2012 15:11:30 -0000 @@ -236,7 +236,8 @@ retry: } } - dirp->dd_len = len; + _DIAGASSERT(__type_fit(int, len)); + dirp->dd_len = (int)len; dirp->dd_size = ddptr - dirp->dd_buf; } else { dirp->dd_len = incr; Index: gen/psignal.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/psignal.c,v retrieving revision 1.22 diff -u -p -u -r1.22 psignal.c --- gen/psignal.c 27 Aug 2010 08:38:41 -0000 1.22 +++ gen/psignal.c 11 Mar 2012 15:11:30 -0000 @@ -75,7 +75,7 @@ psignal(int sig, const char *s) v++; v->iov_base = __UNCONST("\n"); v->iov_len = 1; - (void)writev(STDERR_FILENO, iov, (v - iov) + 1); + (void)writev(STDERR_FILENO, iov, (int)((v - iov) + 1)); } void Index: gen/pw_scan.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/pw_scan.c,v retrieving revision 1.22 diff -u -p -u -r1.22 pw_scan.c --- gen/pw_scan.c 29 Jan 2009 10:41:39 -0000 1.22 +++ gen/pw_scan.c 11 Mar 2012 15:11:30 -0000 @@ -60,7 +60,7 @@ __RCSID("$NetBSD: pw_scan.c,v 1.22 2009/ #endif /* ! HAVE_NBTOOL_CONFIG_H */ static int -gettime(long long *res, const char *p, int *flags, int dowarn, int flag) +gettime(time_t *res, const char *p, int *flags, int dowarn, int flag) { long long l; char *ep; @@ -80,8 +80,8 @@ gettime(long long *res, const char *p, i vp = strerror(errno); goto done; } - - *res = l; + _DIAGASSERT(__type_fit(time_t, l)); + *res = (time_t)l; return 1; done: if (dowarn) { @@ -135,7 +135,7 @@ pw_scan( char *bp, struct passwd *pw, in #endif { unsigned long id; - long long ti; + time_t ti; int root, inflags; int dowarn; const char *p, *sh; Index: gen/scandir.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/scandir.c,v retrieving revision 1.26 diff -u -p -u -r1.26 scandir.c --- gen/scandir.c 9 Jun 2007 23:57:25 -0000 1.26 +++ gen/scandir.c 11 Mar 2012 15:11:30 -0000 @@ -139,7 +139,8 @@ scandir(const char *dirname, struct dire if (nitems && dcomp != NULL) qsort(names, nitems, sizeof(*names), dcomp); *namelist = names; - return nitems; + _DIAGASSERT(__type_fit(int, nitems)); + return (int)nitems; bad2: while (nitems-- > 0) Index: gen/sysctl.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/sysctl.c,v retrieving revision 1.30 diff -u -p -u -r1.30 sysctl.c --- gen/sysctl.c 27 Aug 2008 08:56:49 -0000 1.30 +++ gen/sysctl.c 11 Mar 2012 15:11:30 -0000 @@ -43,6 +43,7 @@ __RCSID("$NetBSD: sysctl.c,v 1.30 2008/0 #define __COMPAT_SYSCTL #include <sys/sysctl.h> +#include <assert.h> #include <errno.h> #include <paths.h> #include <stdio.h> @@ -317,10 +318,13 @@ user_sysctl(name, namelen, oldp, oldlenp if (sysctl_usermib[ni].sysctl_desc == NULL) d1->descr_len = 1; else { + size_t dlen; (void)strlcpy(d1->descr_str, sysctl_usermib[ni].sysctl_desc, sizeof(buf) - sizeof(*d1)); - d1->descr_len = strlen(d1->descr_str) + 1; + dlen = strlen(d1->descr_str) + 1; + _DIAGASSERT(__type_fit(uint32_t, dlen)); + d1->descr_len = (uint32_t)dlen; } d = (size_t)__sysc_desc_adv(NULL, d1->descr_len); if (d2 != NULL) Index: gen/sysctlgetmibinfo.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/sysctlgetmibinfo.c,v retrieving revision 1.9 diff -u -p -u -r1.9 sysctlgetmibinfo.c --- gen/sysctlgetmibinfo.c 13 Dec 2010 23:10:13 -0000 1.9 +++ gen/sysctlgetmibinfo.c 11 Mar 2012 15:11:30 -0000 @@ -43,6 +43,7 @@ __RCSID("$NetBSD: sysctlgetmibinfo.c,v 1 #include <sys/param.h> #include <sys/sysctl.h> +#include <assert.h> #include <errno.h> #include <inttypes.h> #include <stdlib.h> @@ -131,7 +132,8 @@ relearnhead(void) { struct sysctlnode *h, *i, *o, qnode; size_t si, so; - int rc, name, nlen, olen, ni, oi; + int rc, name; + size_t nlen, olen, ni, oi; uint32_t t; /* @@ -165,7 +167,7 @@ relearnhead(void) * order the new copy of the head */ nlen = so / sizeof(struct sysctlnode); - qsort(h, (size_t)nlen, sizeof(struct sysctlnode), compar); + qsort(h, nlen, sizeof(struct sysctlnode), compar); /* * verify that everything is the same. if it is, we don't @@ -259,8 +261,9 @@ relearnhead(void) /* * pop new head in */ - sysctl_mibroot.sysctl_clen = nlen; - sysctl_mibroot.sysctl_csize = nlen; + _DIAGASSERT(__type_fit(uint32_t, nlen)); + sysctl_mibroot.sysctl_csize = + sysctl_mibroot.sysctl_clen = (uint32_t)nlen; sysctl_mibroot.sysctl_child = h; free(o); } @@ -330,9 +333,9 @@ __learn_tree(int *name, u_int namelen, s /* * how many did we get? */ - pnode->sysctl_clen = sz / sizeof(struct sysctlnode); - pnode->sysctl_csize = sz / sizeof(struct sysctlnode); - if (pnode->sysctl_clen * sizeof(struct sysctlnode) != sz) { + sz /= sizeof(struct sysctlnode); + pnode->sysctl_csize = pnode->sysctl_clen = (uint32_t)sz; + if (pnode->sysctl_clen != sz) { free(pnode->sysctl_child); pnode->sysctl_child = NULL; errno = EINVAL; Index: gen/sysctlnametomib.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/sysctlnametomib.c,v retrieving revision 1.6 diff -u -p -u -r1.6 sysctlnametomib.c --- gen/sysctlnametomib.c 13 Dec 2010 23:10:13 -0000 1.6 +++ gen/sysctlnametomib.c 11 Mar 2012 15:11:30 -0000 @@ -39,6 +39,7 @@ __RCSID("$NetBSD: sysctlnametomib.c,v 1. #endif #include <sys/param.h> #include <sys/sysctl.h> +#include <assert.h> #ifdef RUMP_ACTION #include <rump/rump_syscalls.h> @@ -61,7 +62,8 @@ sysctlnametomib(const char *gname, int * u_int unamelen; int rc; - unamelen = *namelenp; + _DIAGASSERT(__type_fit(u_int, *namelenp)); + unamelen = (u_int)*namelenp; rc = sysctlgetmibinfo(gname, iname, &unamelen, NULL, NULL, NULL, SYSCTL_VERSION); *namelenp = unamelen; Index: gen/syslog.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/syslog.c,v retrieving revision 1.49 diff -u -p -u -r1.49 syslog.c --- gen/syslog.c 15 Oct 2011 23:00:01 -0000 1.49 +++ gen/syslog.c 11 Mar 2012 15:11:30 -0000 @@ -505,7 +505,7 @@ connectlog_r(struct syslog_data *data) if (!data->connected) { if (connect(data->log_file, (const struct sockaddr *)(const void *)&sun, - sizeof(sun)) == -1) { + (socklen_t)sizeof(sun)) == -1) { (void)close(data->log_file); data->log_file = -1; } else Index: gen/time.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/time.c,v retrieving revision 1.11 diff -u -p -u -r1.11 time.c --- gen/time.c 11 Jan 2009 02:46:27 -0000 1.11 +++ gen/time.c 11 Mar 2012 15:11:30 -0000 @@ -52,6 +52,6 @@ time(time_t *t) if (gettimeofday(&tt, NULL) == -1) return (time_t)-1; if (t != NULL) - *t = tt.tv_sec; - return tt.tv_sec; + *t = (time_t)tt.tv_sec; + return (time_t)tt.tv_sec; } Index: gen/unvis.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/unvis.c,v retrieving revision 1.38 diff -u -p -u -r1.38 unvis.c --- gen/unvis.c 18 Nov 2011 20:28:17 -0000 1.38 +++ gen/unvis.c 11 Mar 2012 15:11:30 -0000 @@ -519,7 +519,7 @@ strnunvisx(char *dst, size_t dlen, const errno = EINVAL; return -1; default: - _DIAGASSERT(0); + _DIAGASSERT(/*CONSTCOND*/0); errno = EINVAL; return -1; } Index: gen/utmpx.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/utmpx.c,v retrieving revision 1.28 diff -u -p -u -r1.28 utmpx.c --- gen/utmpx.c 15 Oct 2011 23:00:02 -0000 1.28 +++ gen/utmpx.c 11 Mar 2012 15:11:30 -0000 @@ -76,7 +76,7 @@ old2new(struct utmpx *utx) struct timeval *tv = &utx->ut_tv; (void)memcpy(&otv, tv, sizeof(otv)); tv->tv_sec = otv.tv_sec; - tv->tv_usec = otv.tv_usec; + tv->tv_usec = (suseconds_t)otv.tv_usec; } static void Index: gmon/gmon.c =================================================================== RCS file: /cvsroot/src/lib/libc/gmon/gmon.c,v retrieving revision 1.33 diff -u -p -u -r1.33 gmon.c --- gmon/gmon.c 5 Jan 2011 00:03:52 -0000 1.33 +++ gmon/gmon.c 11 Mar 2012 15:11:31 -0000 @@ -228,7 +228,7 @@ _m_gmon_alloc(void) cp = mmap(NULL, (size_t)(sizeof (struct gmonparam) + _gmonparam.fromssize + _gmonparam.tossize), - PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0LL); + PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0); p = (void *)cp; *p = _gmonparam; p->kcount = NULL; Index: inet/inet_cidr_ntop.c =================================================================== RCS file: /cvsroot/src/lib/libc/inet/inet_cidr_ntop.c,v retrieving revision 1.7 diff -u -p -u -r1.7 inet_cidr_ntop.c --- inet/inet_cidr_ntop.c 12 Apr 2009 17:07:16 -0000 1.7 +++ inet/inet_cidr_ntop.c 11 Mar 2012 15:11:31 -0000 @@ -35,6 +35,7 @@ __RCSID("$NetBSD: inet_cidr_ntop.c,v 1.7 #include <arpa/nameser.h> #include <arpa/inet.h> +#include <assert.h> #include <errno.h> #include <stdio.h> #include <string.h> @@ -101,7 +102,8 @@ decoct(const u_char *src, size_t bytes, } size -= (size_t)(dst - t); } - return (dst - odst); + _DIAGASSERT(__type_fit(int, dst - odst)); + return (int)(dst - odst); } /*% Index: inet/inet_cidr_pton.c =================================================================== RCS file: /cvsroot/src/lib/libc/inet/inet_cidr_pton.c,v retrieving revision 1.6 diff -u -p -u -r1.6 inet_cidr_pton.c --- inet/inet_cidr_pton.c 12 Apr 2009 17:07:16 -0000 1.6 +++ inet/inet_cidr_pton.c 11 Mar 2012 15:11:31 -0000 @@ -40,6 +40,7 @@ __RCSID("$NetBSD: inet_cidr_pton.c,v 1.6 #include <errno.h> #include <stdio.h> #include <string.h> +#include <stddef.h> #include <stdlib.h> #include "port_after.h" @@ -96,7 +97,8 @@ static const char digits[] = "0123456789 static int inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits, int ipv6) { const u_char *odst = dst; - int n, ch, tmp, bits; + int ch, bits; + ptrdiff_t n, tmp; size_t size = 4; /* Get the mantissa. */ @@ -188,7 +190,7 @@ inet_cidr_pton_ipv6(const char *src, u_c pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (val > 0xffff) return (0); saw_xdigit = 1; @@ -237,7 +239,7 @@ inet_cidr_pton_ipv6(const char *src, u_c * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) @@ -276,7 +278,7 @@ getbits(const char *src, int ipv6) { if (cp == NULL) /*%< syntax */ return (-2); bits *= 10; - bits += cp - digits; + bits += (int)(cp - digits); if (bits == 0 && *src != '\0') /*%< no leading zeros */ return (-2); if (bits > (ipv6 ? 128 : 32)) /*%< range error */ Index: inet/inet_net_pton.c =================================================================== RCS file: /cvsroot/src/lib/libc/inet/inet_net_pton.c,v retrieving revision 1.2 diff -u -p -u -r1.2 inet_net_pton.c --- inet/inet_net_pton.c 6 Mar 2011 16:00:20 -0000 1.2 +++ inet/inet_net_pton.c 11 Mar 2012 15:11:31 -0000 @@ -34,6 +34,7 @@ __RCSID("$NetBSD: inet_net_pton.c,v 1.2 #include <arpa/inet.h> #include <isc/assertions.h> +#include <stddef.h> #include <ctype.h> #include <errno.h> #include <stdio.h> @@ -73,9 +74,11 @@ static int inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { static const char xdigits[] = "0123456789abcdef"; static const char digits[] = "0123456789"; - int n, ch, tmp = 0, dirty, bits; + int ch, dirty, bits; + ptrdiff_t n, tmp; const u_char *odst = dst; + tmp = 0; ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') && isascii((u_char)(src[1])) @@ -144,7 +147,7 @@ inet_net_pton_ipv4( const char *src, u_c n = strchr(digits, ch) - digits; INSIST(n >= 0 && n <= 9); bits *= 10; - bits += n; + bits += (int)n; if (bits > 32) goto emsgsize; } while ((ch = *src++) != '\0' && isascii((u_char)ch) @@ -174,7 +177,7 @@ inet_net_pton_ipv4( const char *src, u_c bits = 8; /* If imputed mask is narrower than specified octets, widen. */ if (bits >= 8 && bits < ((dst - odst) * 8)) - bits = (dst - odst) * 8; + bits = (int)(dst - odst) * 8; } /* Extend network to cover the actual mask. */ while (bits > ((dst - odst) * 8)) { @@ -210,7 +213,7 @@ getbits(const char *src, int *bitsp) { if (n++ != 0 && val == 0) /* no leading zeros */ return (0); val *= 10; - val += (pch - digits); + val += (int)(pch - digits); if (val > 128) /* range */ return (0); continue; @@ -241,7 +244,7 @@ getv4(const char *src, u_char *dst, int if (n++ != 0 && val == 0) /* no leading zeros */ return (0); val *= 10; - val += (pch - digits); + val += (int)(pch - digits); if (val > 255) /* range */ return (0); continue; @@ -300,7 +303,7 @@ inet_net_pton_ipv6(const char *src, u_ch pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (++digits > 4) goto enoent; saw_xdigit = 1; @@ -356,7 +359,7 @@ inet_net_pton_ipv6(const char *src, u_ch * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) Index: inet/inet_neta.c =================================================================== RCS file: /cvsroot/src/lib/libc/inet/inet_neta.c,v retrieving revision 1.1 diff -u -p -u -r1.1 inet_neta.c --- inet/inet_neta.c 20 May 2004 23:13:02 -0000 1.1 +++ inet/inet_neta.c 11 Mar 2012 15:11:31 -0000 @@ -73,8 +73,8 @@ inet_neta(src, dst, size) ep = dst + size; if (ep <= dst) goto emsgsize; - while (src & 0xffffffff) { - u_char b = (u_char)((src & 0xff000000) >> 24); + while (src & 0xffffffffUL) { + u_char b = (u_char)((src & 0xff000000UL) >> 24); src <<= 8; if (b || src) { Index: inet/inet_ntoa.c =================================================================== RCS file: /cvsroot/src/lib/libc/inet/inet_ntoa.c,v retrieving revision 1.1 diff -u -p -u -r1.1 inet_ntoa.c --- inet/inet_ntoa.c 20 May 2004 23:13:02 -0000 1.1 +++ inet/inet_ntoa.c 11 Mar 2012 15:11:31 -0000 @@ -59,6 +59,6 @@ inet_ntoa(struct in_addr in) { static char ret[18]; strlcpy(ret, "[inet_ntoa error]", sizeof(ret)); - (void) inet_ntop(AF_INET, &in, ret, sizeof ret); - return (ret); + (void) inet_ntop(AF_INET, &in, ret, (socklen_t)sizeof ret); + return ret; } Index: inet/inet_pton.c =================================================================== RCS file: /cvsroot/src/lib/libc/inet/inet_pton.c,v retrieving revision 1.7 diff -u -p -u -r1.7 inet_pton.c --- inet/inet_pton.c 12 Apr 2009 17:07:17 -0000 1.7 +++ inet/inet_pton.c 11 Mar 2012 15:11:31 -0000 @@ -35,6 +35,7 @@ __RCSID("$NetBSD: inet_pton.c,v 1.7 2009 #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> +#include <stddef.h> #include <string.h> #include <assert.h> #include <ctype.h> @@ -100,10 +101,10 @@ inet_pton4(const char *src, u_char *dst, { u_int32_t val; u_int digit, base; - int n; + ptrdiff_t n; unsigned char c; u_int parts[4]; - register u_int *pp = parts; + u_int *pp = parts; _DIAGASSERT(src != NULL); _DIAGASSERT(dst != NULL); @@ -248,7 +249,7 @@ inet_pton6(const char *src, u_char *dst) pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (++seen_xdigits > 4) return (0); continue; @@ -289,7 +290,7 @@ inet_pton6(const char *src, u_char *dst) * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) Index: isc/ev_timers.c =================================================================== RCS file: /cvsroot/src/lib/libc/isc/ev_timers.c,v retrieving revision 1.8 diff -u -p -u -r1.8 ev_timers.c --- isc/ev_timers.c 12 Apr 2009 17:07:17 -0000 1.8 +++ isc/ev_timers.c 11 Mar 2012 15:11:31 -0000 @@ -176,7 +176,7 @@ evTimeVal(struct timespec ts) { struct timeval tv; tv.tv_sec = ts.tv_sec; - tv.tv_usec = ts.tv_nsec / 1000; + tv.tv_usec = (suseconds_t)(ts.tv_nsec / 1000); return (tv); } Index: md/mdXhl.c =================================================================== RCS file: /cvsroot/src/lib/libc/md/mdXhl.c,v retrieving revision 1.8 diff -u -p -u -r1.8 mdXhl.c --- md/mdXhl.c 6 Mar 2009 18:15:24 -0000 1.8 +++ md/mdXhl.c 11 Mar 2012 15:11:31 -0000 @@ -78,7 +78,8 @@ MDNAME(File)(filename, buf) { unsigned char buffer[BUFSIZ]; MDNAME(_CTX) ctx; - int f, i, j; + int f, j; + ssize_t i; _DIAGASSERT(filename != 0); /* buf may be NULL */ Index: misc/stack_protector.c =================================================================== RCS file: /cvsroot/src/lib/libc/misc/stack_protector.c,v retrieving revision 1.7 diff -u -p -u -r1.7 stack_protector.c --- misc/stack_protector.c 8 Dec 2011 02:27:14 -0000 1.7 +++ misc/stack_protector.c 11 Mar 2012 15:11:31 -0000 @@ -63,8 +63,8 @@ __guard_setup(void) return; len = sizeof(__stack_chk_guard); - if (__sysctl(mib, __arraycount(mib), __stack_chk_guard, &len, NULL, 0) == -1 || - len != sizeof(__stack_chk_guard)) { + if (__sysctl(mib, (u_int)__arraycount(mib), __stack_chk_guard, &len, + NULL, 0) == -1 || len != sizeof(__stack_chk_guard)) { /* If sysctl was unsuccessful, use the "terminator canary". */ ((unsigned char *)(void *)__stack_chk_guard)[0] = 0; ((unsigned char *)(void *)__stack_chk_guard)[1] = 0; Index: nameser/ns_name.c =================================================================== RCS file: /cvsroot/src/lib/libc/nameser/ns_name.c,v retrieving revision 1.8 diff -u -p -u -r1.8 ns_name.c --- nameser/ns_name.c 12 Apr 2009 19:43:37 -0000 1.8 +++ nameser/ns_name.c 11 Mar 2012 15:11:32 -0000 @@ -33,6 +33,7 @@ __RCSID("$NetBSD: ns_name.c,v 1.8 2009/0 #include <netinet/in.h> #include <arpa/nameser.h> +#include <assert.h> #include <errno.h> #include <resolv.h> #include <string.h> @@ -43,9 +44,9 @@ __RCSID("$NetBSD: ns_name.c,v 1.8 2009/0 #include "port_after.h" #ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) +# define SPRINTF(x) ((int)strlen(sprintf/**/x)) #else -# define SPRINTF(x) ((size_t)sprintf x) +# define SPRINTF(x) (sprintf x) #endif #define NS_TYPE_ELT 0x40 /*%< EDNS0 extended label type */ @@ -189,7 +190,8 @@ ns_name_ntop(const u_char *src, char *ds return (-1); } *dn++ = '\0'; - return (dn - dst); + _DIAGASSERT(__type_fit(int, dn - dst)); + return (int)(dn - dst); } /*% @@ -256,19 +258,19 @@ ns_name_pton2(const char *src, u_char *d continue; } else if ((cp = strchr(digits, c)) != NULL) { - n = (cp - digits) * 100; + n = (int)(cp - digits) * 100; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { errno = EMSGSIZE; return (-1); } - n += (cp - digits) * 10; + n += (int)(cp - digits) * 10; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { errno = EMSGSIZE; return (-1); } - n += (cp - digits); + n += (int)(cp - digits); if (n > 255) { errno = EMSGSIZE; return (-1); @@ -280,7 +282,7 @@ ns_name_pton2(const char *src, u_char *d escaped = 1; continue; } else if (c == '.') { - c = (bp - label - 1); + c = (int)(bp - label - 1); if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); @@ -320,7 +322,7 @@ ns_name_pton2(const char *src, u_char *d } *bp++ = (u_char)c; } - c = (bp - label - 1); + c = (int)(bp - label - 1); if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); @@ -398,7 +400,8 @@ ns_name_ntol(const u_char *src, u_char * } } *dn++ = '\0'; - return (dn - dst); + _DIAGASSERT(__type_fit(int, dn - dst)); + return (int)(dn - dst); } /*% @@ -466,8 +469,10 @@ ns_name_unpack2(const u_char *msg, const errno = EMSGSIZE; return (-1); } - if (len < 0) - len = srcp - src + 1; + if (len < 0) { + _DIAGASSERT(__type_fit(int, srcp - src + 1)); + len = (int)(srcp - src + 1); + } srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); if (srcp < msg || srcp >= eom) { /*%< Out of range. */ errno = EMSGSIZE; @@ -493,9 +498,11 @@ ns_name_unpack2(const u_char *msg, const *dstp++ = 0; if (dstlen != NULL) *dstlen = dstp - dst; - if (len < 0) - len = srcp - src; - return (len); + if (len < 0) { + _DIAGASSERT(__type_fit(int, srcp - src)); + len = (int)(srcp - src); + } + return len; } /*% @@ -575,7 +582,8 @@ ns_name_pack(const u_char *src, u_char * } *dstp++ = ((u_int32_t)l >> 8) | NS_CMPRSFLGS; *dstp++ = l % 256; - return (dstp - dst); + _DIAGASSERT(__type_fit(int, dstp - dst)); + return (int)(dstp - dst); } /* Not found, save it. */ if (lastdnptr != NULL && cpp < lastdnptr - 1 && @@ -606,7 +614,8 @@ cleanup: errno = EMSGSIZE; return (-1); } - return (dstp - dst); + _DIAGASSERT(__type_fit(int, dstp - dst)); + return (int)(dstp - dst); } /*% @@ -960,8 +969,11 @@ dn_find(const u_char *domain, const u_ch mklower(*cp++)) goto next; /* Is next root for both ? */ - if (*dn == '\0' && *cp == '\0') - return (sp - msg); + if (*dn == '\0' && *cp == '\0') { + _DIAGASSERT(__type_fit(int, + sp - msg)); + return (int)(sp - msg); + } if (*dn) continue; goto next; @@ -992,7 +1004,7 @@ decode_bitstring(const unsigned char **c if ((blen = (*cp & 0xff)) == 0) blen = 256; plen = (blen + 3) / 4; - plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); + plen += (int)sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); if (dn + plen >= eom) return (-1); @@ -1027,7 +1039,8 @@ decode_bitstring(const unsigned char **c dn += i; *cpp = cp; - return (dn - beg); + _DIAGASSERT(__type_fit(int, dn - beg)); + return (int)(dn - beg); } static int Index: nameser/ns_netint.c =================================================================== RCS file: /cvsroot/src/lib/libc/nameser/ns_netint.c,v retrieving revision 1.6 diff -u -p -u -r1.6 ns_netint.c --- nameser/ns_netint.c 12 Apr 2009 17:07:17 -0000 1.6 +++ nameser/ns_netint.c 11 Mar 2012 15:11:32 -0000 @@ -36,29 +36,29 @@ __RCSID("$NetBSD: ns_netint.c,v 1.6 2009 /* Public. */ -u_int16_t +uint16_t ns_get16(const u_char *src) { - u_int dst; + uint16_t dst; NS_GET16(dst, src); - return (dst); + return dst; } -u_int32_t +uint32_t ns_get32(const u_char *src) { - u_long dst; + u_int32_t dst; NS_GET32(dst, src); - return (dst); + return dst; } void -ns_put16(u_int16_t src, u_char *dst) { +ns_put16(uint16_t src, u_char *dst) { NS_PUT16(src, dst); } void -ns_put32(u_int32_t src, u_char *dst) { +ns_put32(uint32_t src, u_char *dst) { NS_PUT32(src, dst); } Index: nameser/ns_parse.c =================================================================== RCS file: /cvsroot/src/lib/libc/nameser/ns_parse.c,v retrieving revision 1.8 diff -u -p -u -r1.8 ns_parse.c --- nameser/ns_parse.c 12 Apr 2009 19:43:37 -0000 1.8 +++ nameser/ns_parse.c 11 Mar 2012 15:11:32 -0000 @@ -35,6 +35,7 @@ __RCSID("$NetBSD: ns_parse.c,v 1.8 2009/ #include <netinet/in.h> #include <arpa/nameser.h> +#include <assert.h> #include <errno.h> #include <resolv.h> #include <string.h> @@ -104,7 +105,8 @@ ns_skiprr(const u_char *ptr, const u_cha } if (ptr > eom) RETERR(EMSGSIZE); - return (ptr - optr); + _DIAGASSERT(__type_fit(int, ptr - optr)); + return (int)(ptr - optr); } int Index: nameser/ns_print.c =================================================================== RCS file: /cvsroot/src/lib/libc/nameser/ns_print.c,v retrieving revision 1.10 diff -u -p -u -r1.10 ns_print.c --- nameser/ns_print.c 12 Apr 2009 19:43:37 -0000 1.10 +++ nameser/ns_print.c 11 Mar 2012 15:11:32 -0000 @@ -39,17 +39,19 @@ __RCSID("$NetBSD: ns_print.c,v 1.10 2009 #include <isc/assertions.h> #include <isc/dst.h> +#include <assert.h> #include <errno.h> #include <resolv.h> +#include <stddef.h> #include <string.h> #include <ctype.h> #include "port_after.h" #ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) +# define SPRINTF(x) ((int)strlen(sprintf/**/x)) #else -# define SPRINTF(x) ((size_t)sprintf x) +# define SPRINTF(x) (sprintf x) #endif /* Forward. */ @@ -126,7 +128,7 @@ ns_sprintrrf(const u_char *msg, size_t m if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) { T(addstr("\t\t\t", (size_t)3, &buf, &buflen)); } else { - len = prune_origin(name, origin); + len = (int)prune_origin(name, origin); if (*name == '\0') { goto root; } else if (len == 0) { @@ -161,7 +163,7 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_a: if (rdlen != (size_t)NS_INADDRSZ) goto formerr; - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); break; @@ -331,7 +333,7 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_aaaa: if (rdlen != (size_t)NS_IN6ADDRSZ) goto formerr; - (void) inet_ntop(AF_INET6, rdata, buf, buflen); + (void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); break; @@ -422,7 +424,7 @@ ns_sprintrrf(const u_char *msg, size_t m goto formerr; /* Address. */ - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += NS_INADDRSZ; @@ -565,7 +567,7 @@ ns_sprintrrf(const u_char *msg, size_t m } case ns_t_nxt: { - int n, c; + ptrdiff_t n, c; /* Next domain name. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); @@ -574,7 +576,7 @@ ns_sprintrrf(const u_char *msg, size_t m n = edata - rdata; for (c = 0; c < n*8; c++) if (NS_NXT_BIT_ISSET(c, rdata)) { - len = SPRINTF((tmp, " %s", p_type(c))); + len = SPRINTF((tmp, " %s", p_type((int)c))); T(addstr(tmp, (size_t)len, &buf, &buflen)); } break; @@ -583,7 +585,7 @@ ns_sprintrrf(const u_char *msg, size_t m case ns_t_cert: { u_int c_type, key_tag, alg; int n; - unsigned int siz; + size_t siz; char base64_cert[8192], tmp1[40]; const char *leader; @@ -689,7 +691,7 @@ ns_sprintrrf(const u_char *msg, size_t m if (rdata + pbyte >= edata) goto formerr; memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte); - (void) inet_ntop(AF_INET6, &a, buf, buflen); + (void) inet_ntop(AF_INET6, &a, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += sizeof(a) - pbyte; } @@ -885,7 +887,7 @@ ns_sprintrrf(const u_char *msg, size_t m char base64_dhcid[8192]; const char *leader; - siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ + siz = (int)(edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_dhcid) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); @@ -961,12 +963,12 @@ ns_sprintrrf(const u_char *msg, size_t m T(addstr(".", 1, &buf, &buflen)); break; case 1: - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += 4; break; case 2: - (void) inet_ntop(AF_INET6, rdata, buf, buflen); + (void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += 16; break; @@ -978,7 +980,7 @@ ns_sprintrrf(const u_char *msg, size_t m if (rdata >= edata) break; - siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ + siz = (int)(edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_key) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); @@ -1056,7 +1058,8 @@ ns_sprintrrf(const u_char *msg, size_t m comment = "unknown RR type"; goto hexify; } - return (buf - obuf); + _DIAGASSERT(__type_fit(int, buf - obuf)); + return (int)(buf - obuf); formerr: comment = "RR format error"; hexify: { @@ -1070,7 +1073,7 @@ ns_sprintrrf(const u_char *msg, size_t m p = tmp; p += SPRINTF((p, "\n\t")); spaced = 0; - n = MIN(16, edata - rdata); + n = MIN(16, (int)(edata - rdata)); for (m = 0; m < n; m++) p += SPRINTF((p, "%02x ", rdata[m])); T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen)); @@ -1087,7 +1090,8 @@ ns_sprintrrf(const u_char *msg, size_t m T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen)); rdata += n; } - return (buf - obuf); + _DIAGASSERT(__type_fit(int, buf - obuf)); + return (int)(buf - obuf); } } @@ -1163,7 +1167,8 @@ charstr(const u_char *rdata, const u_cha } if (addstr("\"", (size_t)1, buf, buflen) < 0) goto enospc; - return (rdata - odata); + _DIAGASSERT(__type_fit(int, rdata - odata)); + return (int)(rdata - odata); enospc: errno = ENOSPC; *buf = save_buf; @@ -1207,7 +1212,8 @@ addname(const u_char *msg, size_t msglen *pp += n; addlen(newlen, buf, buflen); **buf = '\0'; - return (newlen); + _DIAGASSERT(__type_fit(int, newlen)); + return (int)newlen; enospc: errno = ENOSPC; *buf = save_buf; @@ -1238,7 +1244,7 @@ static int addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) { size_t save_buflen = *buflen; char *save_buf = *buf; - int t; + ptrdiff_t t; if (spaced || len >= target - 1) { T(addstr(" ", (size_t)2, buf, buflen)); Index: nameser/ns_ttl.c =================================================================== RCS file: /cvsroot/src/lib/libc/nameser/ns_ttl.c,v retrieving revision 1.7 diff -u -p -u -r1.7 ns_ttl.c --- nameser/ns_ttl.c 12 Apr 2009 17:07:17 -0000 1.7 +++ nameser/ns_ttl.c 11 Mar 2012 15:11:32 -0000 @@ -32,6 +32,7 @@ __RCSID("$NetBSD: ns_ttl.c,v 1.7 2009/04 #include <arpa/nameser.h> +#include <assert.h> #include <ctype.h> #include <errno.h> #include <stdio.h> @@ -61,11 +62,11 @@ ns_format_ttl(u_long src, char *dst, siz int secs, mins, hours, days, weeks, x; char *p; - secs = src % 60; src /= 60; - mins = src % 60; src /= 60; - hours = src % 24; src /= 24; - days = src % 7; src /= 7; - weeks = src; src = 0; + secs = (int)(src % 60); src /= 60; + mins = (int)(src % 60); src /= 60; + hours = (int)(src % 24); src /= 24; + days = (int)(src % 7); src /= 7; + weeks = (int)src; src = 0; x = 0; if (weeks) { @@ -97,7 +98,8 @@ ns_format_ttl(u_long src, char *dst, siz *p = tolower(ch); } - return (dst - odst); + _DIAGASSERT(__type_fit(int, dst - odst)); + return (int)(dst - odst); } #ifndef _LIBC Index: net/base64.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/base64.c,v retrieving revision 1.12 diff -u -p -u -r1.12 base64.c --- net/base64.c 12 Apr 2009 17:07:17 -0000 1.12 +++ net/base64.c 11 Mar 2012 15:11:32 -0000 @@ -203,7 +203,8 @@ b64_ntop(u_char const *src, size_t srcle if (datalength >= targsize) return (-1); target[datalength] = '\0'; /*%< Returned value doesn't count \\0. */ - return (datalength); + _DIAGASSERT(__type_fit(int, datalength)); + return (int)datalength; } /* skips all whitespace anywhere. @@ -244,7 +245,8 @@ b64_pton(src, target, targsize) if (target) { if ((size_t)tarindex >= targsize) return (-1); - target[tarindex] = (pos - Base64) << 2; + target[tarindex] = + (unsigned char)(pos - Base64) << 2; } state = 1; break; @@ -254,8 +256,9 @@ b64_pton(src, target, targsize) return (-1); target[tarindex] |= (u_int32_t)(pos - Base64) >> 4; - target[tarindex+1] = ((pos - Base64) & 0x0f) - << 4 ; + target[tarindex+1] = + (unsigned char) + (((pos - Base64) & 0x0f) << 4); } tarindex++; state = 2; @@ -266,8 +269,9 @@ b64_pton(src, target, targsize) return (-1); target[tarindex] |= (u_int32_t)(pos - Base64) >> 2; - target[tarindex+1] = ((pos - Base64) & 0x03) - << 6; + target[tarindex+1] = + (unsigned char) + (((pos - Base64) & 0x03) << 6); } tarindex++; state = 3; @@ -276,7 +280,8 @@ b64_pton(src, target, targsize) if (target) { if ((size_t)tarindex >= targsize) return (-1); - target[tarindex] |= (pos - Base64); + target[tarindex] |= + (unsigned char)(pos - Base64); } tarindex++; state = 0; @@ -337,7 +342,8 @@ b64_pton(src, target, targsize) return (-1); } - return (tarindex); + _DIAGASSERT(__type_fit(int, tarindex)); + return (int)tarindex; } /*! \file */ Index: net/ethers.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/ethers.c,v retrieving revision 1.21 diff -u -p -u -r1.21 ethers.c --- net/ethers.c 15 Oct 2006 10:55:01 -0000 1.21 +++ net/ethers.c 11 Mar 2012 15:11:32 -0000 @@ -152,7 +152,7 @@ ether_hostton(hostname, e) size_t len; char try[MAXHOSTNAMELEN + 1]; #ifdef YP - int hostlen = strlen(hostname); + int hostlen = (int)strlen(hostname); #endif _DIAGASSERT(hostname != NULL); Index: net/getaddrinfo.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/getaddrinfo.c,v retrieving revision 1.96 diff -u -p -u -r1.96 getaddrinfo.c --- net/getaddrinfo.c 15 Oct 2011 23:00:02 -0000 1.96 +++ net/getaddrinfo.c 11 Mar 2012 15:11:33 -0000 @@ -330,8 +330,8 @@ str2number(const char *p) ep = NULL; errno = 0; v = strtoul(p, &ep, 10); - if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX) - return v; + if (errno == 0 && ep && *ep == '\0' && v <= INT_MAX) + return (int)v; else return -1; } @@ -1112,7 +1112,7 @@ getanswer(const querybuf *answer, int an h_errno = NO_RECOVERY; return (NULL); } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !(*name_ok)(bp)) { h_errno = NO_RECOVERY; return (NULL); @@ -1123,7 +1123,7 @@ getanswer(const querybuf *answer, int an * same as the one we sent; this just gets the expanded name * (i.e., with the succeeding search-domain tacked on). */ - n = strlen(bp) + 1; /* for the \0 */ + n = (int)strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { h_errno = NO_RECOVERY; return (NULL); @@ -1136,7 +1136,7 @@ getanswer(const querybuf *answer, int an haveanswer = 0; had_error = 0; while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !(*name_ok)(bp)) { had_error++; continue; @@ -1155,14 +1155,14 @@ getanswer(const querybuf *answer, int an } if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + n = dn_expand(answer->buf, eom, cp, tbuf, (int)sizeof tbuf); if ((n < 0) || !(*name_ok)(tbuf)) { had_error++; continue; } cp += n; /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ + n = (int)strlen(tbuf) + 1; /* for the \0 */ if (n > ep - bp || n >= MAXHOSTNAMELEN) { had_error++; continue; @@ -1218,7 +1218,7 @@ getanswer(const querybuf *answer, int an int nn; canonname = bp; - nn = strlen(bp) + 1; /* for the \0 */ + nn = (int)strlen(bp) + 1; /* for the \0 */ bp += nn; } @@ -1437,7 +1437,7 @@ _gethtent(FILE **hostf, const char *name if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "re"))) return (NULL); again: - if (!(p = fgets(hostbuf, sizeof hostbuf, *hostf))) + if (!(p = fgets(hostbuf, (int)sizeof hostbuf, *hostf))) return (NULL); if (*p == '#') goto again; @@ -1706,10 +1706,10 @@ res_queryN(const char *name, /* domain n #endif n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL, - buf, sizeof(buf)); + buf, (int)sizeof(buf)); #ifdef RES_USE_EDNS0 if (n > 0 && (res->options & RES_USE_EDNS0) != 0) - n = res_nopt(res, n, buf, sizeof(buf), anslen); + n = res_nopt(res, n, buf, (int)sizeof(buf), anslen); #endif if (n <= 0) { #ifdef DEBUG Index: net/gethnamaddr.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/gethnamaddr.c,v retrieving revision 1.77 diff -u -p -u -r1.77 gethnamaddr.c --- net/gethnamaddr.c 15 Oct 2011 23:00:02 -0000 1.77 +++ net/gethnamaddr.c 11 Mar 2012 15:11:33 -0000 @@ -257,7 +257,7 @@ getanswer(const querybuf *answer, int an h_errno = NO_RECOVERY; return NULL; } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !(*name_ok)(bp)) { h_errno = NO_RECOVERY; return NULL; @@ -268,7 +268,7 @@ getanswer(const querybuf *answer, int an * same as the one we sent; this just gets the expanded name * (i.e., with the succeeding search-domain tacked on). */ - n = strlen(bp) + 1; /* for the \0 */ + n = (int)strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { h_errno = NO_RECOVERY; return NULL; @@ -287,7 +287,7 @@ getanswer(const querybuf *answer, int an haveanswer = 0; had_error = 0; while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !(*name_ok)(bp)) { had_error++; continue; @@ -310,7 +310,7 @@ getanswer(const querybuf *answer, int an if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { if (ap >= &host_aliases[MAXALIASES-1]) continue; - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + n = dn_expand(answer->buf, eom, cp, tbuf, (int)sizeof tbuf); if ((n < 0) || !(*name_ok)(tbuf)) { had_error++; continue; @@ -322,14 +322,14 @@ getanswer(const querybuf *answer, int an } /* Store alias. */ *ap++ = bp; - n = strlen(bp) + 1; /* for the \0 */ + n = (int)strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { had_error++; continue; } bp += n; /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ + n = (int)strlen(tbuf) + 1; /* for the \0 */ if (n > ep - bp || n >= MAXHOSTNAMELEN) { had_error++; continue; @@ -340,7 +340,7 @@ getanswer(const querybuf *answer, int an continue; } if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + n = dn_expand(answer->buf, eom, cp, tbuf, (int)sizeof tbuf); if (n < 0 || !res_dnok(tbuf)) { had_error++; continue; @@ -351,7 +351,7 @@ getanswer(const querybuf *answer, int an return NULL; } /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ + n = (int)strlen(tbuf) + 1; /* for the \0 */ if (n > ep - bp || n >= MAXHOSTNAMELEN) { had_error++; continue; @@ -378,7 +378,7 @@ getanswer(const querybuf *answer, int an cp += n; continue; /* XXX - had_error++ ? */ } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !res_hnok(bp)) { had_error++; break; @@ -396,7 +396,7 @@ getanswer(const querybuf *answer, int an else n = -1; if (n != -1) { - n = strlen(bp) + 1; /* for the \0 */ + n = (int)strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { had_error++; break; @@ -442,7 +442,7 @@ getanswer(const querybuf *answer, int an int nn; host.h_name = bp; - nn = strlen(bp) + 1; /* for the \0 */ + nn = (int)strlen(bp) + 1; /* for the \0 */ bp += nn; } @@ -487,7 +487,7 @@ getanswer(const querybuf *answer, int an if (res->nsort && haveanswer > 1 && qtype == T_A) addrsort(h_addr_ptrs, haveanswer, res); if (!host.h_name) { - n = strlen(qname) + 1; /* for the \0 */ + n = (int)strlen(qname) + 1; /* for the \0 */ if (n > ep - bp || n >= MAXHOSTNAMELEN) goto no_recovery; strlcpy(bp, qname, (size_t)(ep - bp)); @@ -747,7 +747,7 @@ _gethtent(void) return NULL; } again: - if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) { + if (!(p = fgets(hostbuf, (int)sizeof hostbuf, hostf))) { h_errno = HOST_NOT_FOUND; return NULL; } @@ -1002,7 +1002,8 @@ map_v4v6_hostent(struct hostent *hp, cha hp->h_addrtype = AF_INET6; hp->h_length = IN6ADDRSZ; for (ap = hp->h_addr_list; *ap; ap++) { - int i = sizeof(align) - (size_t)((u_long)*bpp % sizeof(align)); + int i = (int)(sizeof(align) - + (size_t)((u_long)*bpp % sizeof(align))); if (ep - *bpp < (i + IN6ADDRSZ)) { /* Out of memory. Truncate address list here. XXX */ @@ -1104,7 +1105,7 @@ _dns_gethtbyname(void *rv, void *cb_data free(buf); return NS_NOTFOUND; } - n = res_nsearch(res, name, C_IN, type, buf->buf, sizeof(buf->buf)); + n = res_nsearch(res, name, C_IN, type, buf->buf, (int)sizeof(buf->buf)); if (n < 0) { free(buf); debugprintf("res_nsearch failed (%d)\n", res, n); @@ -1185,7 +1186,7 @@ _dns_gethtbyaddr(void *rv, void *cb_data free(buf); return NS_NOTFOUND; } - n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf)); + n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf)); if (n < 0) { free(buf); debugprintf("res_nquery failed (%d)\n", res, n); @@ -1370,7 +1371,7 @@ _yp_gethtbyaddr(void *rv, void *cb_data, * XXX unfortunately, we cannot support IPv6 extended scoped address * notation here. gethostbyaddr() is not scope-aware. too bad. */ - if (inet_ntop(af, uaddr, name, sizeof(name)) == NULL) + if (inet_ntop(af, uaddr, name, (socklen_t)sizeof(name)) == NULL) return NS_UNAVAIL; if (__ypcurrent) free(__ypcurrent); Index: net/getifaddrs.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/getifaddrs.c,v retrieving revision 1.14 diff -u -p -u -r1.14 getifaddrs.c --- net/getifaddrs.c 4 Feb 2011 02:01:12 -0000 1.14 +++ net/getifaddrs.c 11 Mar 2012 15:11:33 -0000 @@ -63,10 +63,17 @@ __weak_alias(freeifaddrs,_freeifaddrs) int getifaddrs(struct ifaddrs **pif) { - int icnt = 1; - int dcnt = 0; - int ncnt = 0; - int mib[6]; + size_t icnt = 1; + size_t dcnt = 0; + size_t ncnt = 0; + static const int mib[] = { + CTL_NET, + PF_ROUTE, + 0, /* protocol */ + 0, /* wildcard address family */ + NET_RT_IFLIST, + 0 /* no flags */ + }; size_t needed; char *buf; char *next; @@ -85,17 +92,11 @@ getifaddrs(struct ifaddrs **pif) _DIAGASSERT(pif != NULL); - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; /* protocol */ - mib[3] = 0; /* wildcard address family */ - mib[4] = NET_RT_IFLIST; - mib[5] = 0; /* no flags */ - if (sysctl(mib, __arraycount(mib), NULL, &needed, NULL, 0) < 0) + if (sysctl(mib, (u_int)__arraycount(mib), NULL, &needed, NULL, 0) < 0) return (-1); if ((buf = malloc(needed)) == NULL) return (-1); - if (sysctl(mib, __arraycount(mib), buf, &needed, NULL, 0) < 0) { + if (sysctl(mib, (u_int)__arraycount(mib), buf, &needed, NULL, 0) < 0) { free(buf); return (-1); } Index: net/getnameinfo.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/getnameinfo.c,v retrieving revision 1.50 diff -u -p -u -r1.50 getnameinfo.c --- net/getnameinfo.c 29 Jun 2010 14:44:19 -0000 1.50 +++ net/getnameinfo.c 11 Mar 2012 15:11:33 -0000 @@ -343,8 +343,8 @@ getnameinfo_inet(sa, salen, host, hostle } #endif default: - if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) - == NULL) + if (inet_ntop(afd->a_af, addr, numaddr, + (socklen_t)sizeof(numaddr)) == NULL) return EAI_SYSTEM; numaddrlen = strlen(numaddr); if (numaddrlen + 1 > hostlen) /* don't forget terminator */ @@ -415,7 +415,8 @@ ip6_parsenumeric(sa, addr, host, hostlen _DIAGASSERT(addr != NULL); _DIAGASSERT(host != NULL); - if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL) + if (inet_ntop(AF_INET6, addr, numaddr, (socklen_t)sizeof(numaddr)) + == NULL) return EAI_SYSTEM; numaddrlen = strlen(numaddr); @@ -477,7 +478,7 @@ ip6_sa2str(sa6, buf, bufsiz, flags) bufsiz >= IF_NAMESIZE) { char *p = if_indextoname(ifindex, buf); if (p) { - return(strlen(p)); + return (int)strlen(p); } } Index: net/getnetent.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/getnetent.c,v retrieving revision 1.19 diff -u -p -u -r1.19 getnetent.c --- net/getnetent.c 15 Oct 2011 23:00:02 -0000 1.19 +++ net/getnetent.c 11 Mar 2012 15:11:33 -0000 @@ -129,7 +129,7 @@ getnetent() net.__n_pad0 = 0; #endif again: - p = fgets(line, sizeof line, netf); + p = fgets(line, (int)sizeof line, netf); if (p == NULL) return (NULL); if (*p == '#') Index: net/getnetnamadr.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/getnetnamadr.c,v retrieving revision 1.41 diff -u -p -u -r1.41 getnetnamadr.c --- net/getnetnamadr.c 18 May 2008 22:36:15 -0000 1.41 +++ net/getnetnamadr.c 11 Mar 2012 15:11:33 -0000 @@ -153,7 +153,7 @@ parse_reversed_addr(const char *str, in_ /* build result from octets in reverse */ for (octidx = 3; octidx >= 0; octidx--) { *result <<= 8; - *result |= (octet[octidx] & 0xff); + *result |= (in_addr_t)(octet[octidx] & 0xff); } return 0; } @@ -215,7 +215,7 @@ getnetanswer(querybuf *answer, int ansle haveanswer = 0; n_name[0] = '\0'; while (--ancount >= 0 && cp < eom) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !res_dnok(bp)) break; cp += n; @@ -225,7 +225,7 @@ getnetanswer(querybuf *answer, int ansle cp += INT32SZ; /* TTL */ GETSHORT(n, cp); if (class == C_IN && type == T_PTR) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !res_hnok(bp)) { cp += n; return NULL; @@ -347,7 +347,8 @@ _dns_getnetbyaddr(void *cbrv, void *cbda free(buf); return NS_NOTFOUND; } - anslen = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf)); + anslen = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, + (int)sizeof(buf->buf)); if (anslen < 0) { free(buf); #ifdef DEBUG @@ -459,7 +460,7 @@ _dns_getnetbyname(void *cbrv, void *cbda return NS_NOTFOUND; } anslen = res_nsearch(res, qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); + (int)sizeof(buf->buf)); if (anslen < 0) { free(buf); #ifdef DEBUG Index: net/getservbyname_r.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/getservbyname_r.c,v retrieving revision 1.8 diff -u -p -u -r1.8 getservbyname_r.c --- net/getservbyname_r.c 3 Apr 2011 22:14:15 -0000 1.8 +++ net/getservbyname_r.c 11 Mar 2012 15:11:34 -0000 @@ -78,8 +78,8 @@ _servent_getbyname(struct servent_data * if (namelen + protolen > 255) return NULL; - buf[0] = namelen; - buf[1] = protolen; + buf[0] = (uint8_t)namelen; + buf[1] = (uint8_t)protolen; memcpy(buf + 2, name, namelen); memcpy(buf + 2 + namelen, proto, protolen); Index: net/getservbyport_r.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/getservbyport_r.c,v retrieving revision 1.8 diff -u -p -u -r1.8 getservbyport_r.c --- net/getservbyport_r.c 3 Apr 2011 22:14:15 -0000 1.8 +++ net/getservbyport_r.c 11 Mar 2012 15:11:34 -0000 @@ -77,7 +77,7 @@ _servent_getbyport(struct servent_data * return NULL; buf[0] = 0; - buf[1] = protolen; + buf[1] = (uint8_t)protolen; be16enc(buf + 2, port); memcpy(buf + 4, proto, protolen); Index: net/if_nameindex.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/if_nameindex.c,v retrieving revision 1.6 diff -u -p -u -r1.6 if_nameindex.c --- net/if_nameindex.c 20 Dec 2000 18:47:11 -0000 1.6 +++ net/if_nameindex.c 11 Mar 2012 15:11:34 -0000 @@ -88,8 +88,7 @@ struct if_nameindex * if_nameindex(void) { struct ifaddrs *ifaddrs, *ifa; - unsigned int ni; - int nbytes; + size_t nbytes, ni; struct if_nameindex *ifni, *ifni2; char *cp; Index: net/ip6opt.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/ip6opt.c,v retrieving revision 1.12 diff -u -p -u -r1.12 ip6opt.c --- net/ip6opt.c 30 Jan 2009 23:43:30 -0000 1.12 +++ net/ip6opt.c 11 Mar 2012 15:11:34 -0000 @@ -43,6 +43,7 @@ __RCSID("$NetBSD: ip6opt.c,v 1.12 2009/0 #include <netinet/ip6.h> #include <assert.h> +#include <stddef.h> #include <string.h> #include <stdio.h> @@ -78,8 +79,11 @@ int inet6_option_space(nbytes) int nbytes; { + size_t sp; nbytes += 2; /* we need space for nxt-hdr and length fields */ - return(CMSG_SPACE((nbytes + 7) & ~7)); + sp = CMSG_SPACE((nbytes + 7) & ~7); + _DIAGASSERT(__type_fit(int, sp)); + return (int)sp; } /* @@ -163,7 +167,8 @@ inet6_option_append(cmsg, typep, multx, padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ inet6_insert_padopt(bp, padlen); - cmsg->cmsg_len += padlen; + _DIAGASSERT(__type_fit(socklen_t, padlen + cmsg->cmsg_len)); + cmsg->cmsg_len += (socklen_t)padlen; bp += padlen; /* copy the option */ @@ -173,18 +178,21 @@ inet6_option_append(cmsg, typep, multx, optlen = typep[1] + 2; memcpy(bp, typep, (size_t)optlen); bp += optlen; - cmsg->cmsg_len += optlen; + _DIAGASSERT(__type_fit(socklen_t, optlen + cmsg->cmsg_len)); + cmsg->cmsg_len += (socklen_t)optlen; /* calculate pad length after the option and insert the padding */ off = bp - (u_char *)(void *)eh; padlen = ((off + 7) & ~7) - off; inet6_insert_padopt(bp, padlen); bp += padlen; - cmsg->cmsg_len += padlen; + _DIAGASSERT(__type_fit(socklen_t, padlen + cmsg->cmsg_len)); + cmsg->cmsg_len += (socklen_t)padlen; /* update the length field of the ip6 option header */ off = bp - (u_char *)(void *)eh; - eh->ip6e_len = (off >> 3) - 1; + _DIAGASSERT(__type_fit(uint8_t, (off >> 3) - 1)); + eh->ip6e_len = (uint8_t)((off >> 3) - 1); return(0); } @@ -243,7 +251,7 @@ inet6_option_alloc(cmsg, datalen, multx, padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ inet6_insert_padopt(bp, padlen); - cmsg->cmsg_len += padlen; + cmsg->cmsg_len += (socklen_t)padlen; bp += padlen; /* keep space to store specified length of data */ @@ -256,11 +264,13 @@ inet6_option_alloc(cmsg, datalen, multx, padlen = ((off + 7) & ~7) - off; inet6_insert_padopt(bp, padlen); bp += padlen; - cmsg->cmsg_len += padlen; + _DIAGASSERT(__type_fit(socklen_t, padlen + cmsg->cmsg_len)); + cmsg->cmsg_len += (socklen_t)padlen; /* update the length field of the ip6 option header */ off = bp - (u_char *)(void *)eh; - eh->ip6e_len = (off >> 3) - 1; + _DIAGASSERT(__type_fit(uint8_t, (off >> 3) - 1)); + eh->ip6e_len = (uint8_t)((off >> 3) - 1); return(retval); } @@ -432,7 +442,8 @@ inet6_insert_padopt(u_char *p, size_t le return; default: p[0] = IP6OPT_PADN; - p[1] = len - 2; + _DIAGASSERT(__type_fit(u_char, len - 2)); + p[1] = (u_char)(len - 2); memset(&p[2], 0, len - 2); return; } @@ -496,7 +507,8 @@ inet6_opt_append(void *extbuf, socklen_t padlen = align - (currentlen % align); /* The option must fit in the extension header buffer. */ - currentlen += padlen; + _DIAGASSERT(__type_fit(int, currentlen + padlen)); + currentlen += (int)padlen; if (extlen && /* XXX: right? */ (socklen_t)currentlen > extlen) return (-1); @@ -511,7 +523,8 @@ inet6_opt_append(void *extbuf, socklen_t } else if (padlen > 0) { /* insert a PadN option for alignment */ *optp++ = IP6OPT_PADN; - *optp++ = padlen - 2; + _DIAGASSERT(__type_fit(uint8_t, padlen - 2)); + *optp++ = (uint8_t)(padlen - 2); memset(optp, 0, padlen - 2); optp += (padlen - 2); } @@ -534,7 +547,7 @@ inet6_opt_finish(void *extbuf, socklen_t u_int8_t *padp; size_t padlen = updatelen - offset; - if ((socklen_t)updatelen > extlen) + if ((socklen_t)updatelen > extlen || padlen >= 256 + 2) return (-1); padp = (u_int8_t *)extbuf + offset; @@ -542,7 +555,7 @@ inet6_opt_finish(void *extbuf, socklen_t *padp = IP6OPT_PAD1; else if (padlen > 0) { *padp++ = IP6OPT_PADN; - *padp++ = (padlen - 2); + *padp++ = (uint8_t)(padlen - 2); memset(padp, 0, padlen - 2); } } @@ -582,6 +595,7 @@ inet6_opt_next(void *extbuf, socklen_t e /* Find the next option skipping any padding options. */ while (optp < lim) { + ptrdiff_t rv; switch(*optp) { case IP6OPT_PAD1: optp++; @@ -597,7 +611,9 @@ inet6_opt_next(void *extbuf, socklen_t e *typep = *optp; *lenp = optlen - 2; *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); + rv = optp + optlen - (u_int8_t *)extbuf; + _DIAGASSERT(__type_fit(int, rv)); + return (int)rv; } } @@ -634,9 +650,12 @@ inet6_opt_find(void *extbuf, socklen_t e goto optend; if (*optp == type) { /* found */ + ptrdiff_t td; *lenp = optlen - 2; *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); + td = optp + optlen - (u_int8_t *)extbuf; + _DIAGASSERT(__type_fit(int, td)); + return (int)td; } optp += optlen; Index: net/iso_addr.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/iso_addr.c,v retrieving revision 1.12 diff -u -p -u -r1.12 iso_addr.c --- net/iso_addr.c 29 Nov 2005 03:11:59 -0000 1.12 +++ net/iso_addr.c 11 Mar 2012 15:11:34 -0000 @@ -95,7 +95,8 @@ iso_addr(addr) } break; } while (cp < cplim); - out_addr.isoa_len = cp - out_addr.isoa_genaddr; + _DIAGASSERT(__type_fit(uint8_t, cp - out_addr.isoa_genaddr)); + out_addr.isoa_len = (uint8_t)(cp - out_addr.isoa_genaddr); return (&out_addr); } Index: net/linkaddr.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/linkaddr.c,v retrieving revision 1.14 diff -u -p -u -r1.14 linkaddr.c --- net/linkaddr.c 29 Nov 2005 03:11:59 -0000 1.14 +++ net/linkaddr.c 11 Mar 2012 15:11:34 -0000 @@ -57,14 +57,12 @@ __RCSID("$NetBSD: linkaddr.c,v 1.14 2005 #define LETTER (4*3) void -link_addr(addr, sdl) - register const char *addr; - register struct sockaddr_dl *sdl; +link_addr(const char *addr, struct sockaddr_dl *sdl) { register char *cp = sdl->sdl_data; char *cplim = sdl->sdl_len + (char *)(void *)sdl; - register int byte = 0, state = NAMING; - register int newaddr = 0; /* pacify gcc */ + int byte = 0, state = NAMING; + size_t newaddr = 0; /* pacify gcc */ _DIAGASSERT(addr != NULL); _DIAGASSERT(sdl != NULL); @@ -95,18 +93,19 @@ link_addr(addr, sdl) continue; case NAMING | DELIM: state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; + _DIAGASSERT(__type_fit(uint8_t, cp - sdl->sdl_data)); + sdl->sdl_nlen = (uint8_t)(cp - sdl->sdl_data); continue; case GOTTWO | DIGIT: *cp++ = byte; /* FALLTHROUGH */ case RESET | DIGIT: state = GOTONE; - byte = newaddr; + byte = (int)newaddr; continue; case GOTONE | DIGIT: state = GOTTWO; - byte = newaddr + (byte << 4); + byte = (int)newaddr + (byte << 4); continue; default: /* | DELIM */ state = RESET; @@ -122,10 +121,14 @@ link_addr(addr, sdl) } break; } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); + + _DIAGASSERT(__type_fit(uint8_t, cp - LLADDR(sdl))); + sdl->sdl_alen = (uint8_t)(cp - LLADDR(sdl)); newaddr = cp - (char *)(void *)sdl; - if ((size_t) newaddr > sizeof(*sdl)) - sdl->sdl_len = newaddr; + if (newaddr > sizeof(*sdl)) { + _DIAGASSERT(__type_fit(uint8_t, newaddr)); + sdl->sdl_len = (uint8_t)newaddr; + } return; } Index: net/nsdispatch.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/nsdispatch.c,v retrieving revision 1.36 diff -u -p -u -r1.36 nsdispatch.c --- net/nsdispatch.c 22 Feb 2011 05:45:08 -0000 1.36 +++ net/nsdispatch.c 11 Mar 2012 15:11:34 -0000 @@ -390,8 +390,7 @@ _nsdbtaddsrc(ns_dbt *dbt, const ns_src * /* dbt->srclistsize already incremented */ modkey.name = src->name; - mod = bsearch(&modkey, _nsmod, _nsmodsize, sizeof(*_nsmod), - _nsmodcmp); + mod = bsearch(&modkey, _nsmod, _nsmodsize, sizeof(*_nsmod), _nsmodcmp); if (mod == NULL) return (_nsloadmod(src->name, NULL)); Index: net/rcmd.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/rcmd.c,v retrieving revision 1.66 diff -u -p -u -r1.66 rcmd.c --- net/rcmd.c 31 May 2011 06:49:26 -0000 1.66 +++ net/rcmd.c 11 Mar 2012 15:11:35 -0000 @@ -246,14 +246,16 @@ resrcmd(struct addrinfo *res, char **aho hbuf[0] = '\0'; if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) + hbuf, (socklen_t)sizeof(hbuf), NULL, 0, niflags) != + 0) strlcpy(hbuf, "(invalid)", sizeof(hbuf)); errno = oerrno; warn("rcmd: connect to address %s", hbuf); r = r->ai_next; hbuf[0] = '\0'; if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) + hbuf, (socklen_t)sizeof(hbuf), NULL, 0, niflags) != + 0) strlcpy(hbuf, "(invalid)", sizeof(hbuf)); (void)fprintf(stderr, "Trying %s...\n", hbuf); continue; @@ -318,7 +320,8 @@ resrcmd(struct addrinfo *res, char **aho case AF_INET6: #endif if (getnameinfo((struct sockaddr *)(void *)&from, len, - NULL, 0, num, sizeof(num), NI_NUMERICSERV) != 0 || + NULL, 0, num, (socklen_t)sizeof(num), + NI_NUMERICSERV) != 0 || (atoi(num) >= IPPORT_RESERVED || atoi(num) < IPPORT_RESERVED / 2)) { warnx( @@ -625,7 +628,8 @@ iruserok(u_int32_t raddr, int superuser, irsin.sin_len = sizeof(irsin); #endif memcpy(&irsin.sin_addr, &raddr, sizeof(irsin.sin_addr)); - return iruserok_sa(&irsin, sizeof(irsin), superuser, ruser, luser); + return iruserok_sa(&irsin, (socklen_t)sizeof(irsin), superuser, ruser, + luser); } /* @@ -740,7 +744,7 @@ __ivaliduser(FILE *hostf, u_int32_t radd #endif memcpy(&ivusin.sin_addr, &raddr, sizeof(ivusin.sin_addr)); return __ivaliduser_sa(hostf, (struct sockaddr *)(void *)&ivusin, - sizeof(ivusin), luser, ruser); + (socklen_t)sizeof(ivusin), luser, ruser); } #ifdef notdef /*_LIBC*/ @@ -765,7 +769,7 @@ __ivaliduser_sa(FILE *hostf, const struc _DIAGASSERT(luser != NULL); _DIAGASSERT(ruser != NULL); - while (fgets(buf, sizeof(buf), hostf)) { + while (fgets(buf, (int)sizeof(buf), hostf)) { p = buf; /* Skip lines that are too long. */ if (strchr(p, '\n') == NULL) { @@ -909,7 +913,8 @@ __icheckhost(const struct sockaddr *radd _DIAGASSERT(lhost != NULL); h1[0] = '\0'; - if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0, niflags) != 0) + if (getnameinfo(raddr, salen, h1, (socklen_t)sizeof(h1), NULL, 0, + niflags) != 0) return 0; /* Resolve laddr into sockaddr */ @@ -926,8 +931,8 @@ __icheckhost(const struct sockaddr *radd */ for (r = res; r; r = r->ai_next) { h2[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2), - NULL, 0, niflags) != 0) + if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, + (socklen_t)sizeof(h2), NULL, 0, niflags) != 0) continue; if (strcmp(h1, h2) == 0) { freeaddrinfo(res); @@ -957,10 +962,11 @@ __gethostloop(const struct sockaddr *rad _DIAGASSERT(raddr != NULL); h1[0] = remotehost[0] = '\0'; - if (getnameinfo(raddr, salen, remotehost, sizeof(remotehost), + if (getnameinfo(raddr, salen, remotehost, (socklen_t)sizeof(remotehost), NULL, 0, NI_NAMEREQD) != 0) return NULL; - if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0, niflags) != 0) + if (getnameinfo(raddr, salen, h1, (socklen_t)sizeof(h1), NULL, 0, + niflags) != 0) return NULL; /* @@ -978,8 +984,8 @@ __gethostloop(const struct sockaddr *rad for (r = res; r; r = r->ai_next) { h2[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2), - NULL, 0, niflags) != 0) + if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, + (socklen_t)sizeof(h2), NULL, 0, niflags) != 0) continue; if (strcmp(h1, h2) == 0) { freeaddrinfo(res); Index: net/rthdr.c =================================================================== RCS file: /cvsroot/src/lib/libc/net/rthdr.c,v retrieving revision 1.17 diff -u -p -u -r1.17 rthdr.c --- net/rthdr.c 5 Feb 2009 23:22:39 -0000 1.17 +++ net/rthdr.c 11 Mar 2012 15:11:35 -0000 @@ -67,8 +67,7 @@ __weak_alias(inet6_rth_getaddr, _inet6_r */ size_t -inet6_rthdr_space(type, seg) - int type, seg; +inet6_rthdr_space(int type, int seg) { switch (type) { case IPV6_RTHDR_TYPE_0: @@ -82,9 +81,7 @@ inet6_rthdr_space(type, seg) } struct cmsghdr * -inet6_rthdr_init(bp, type) - void *bp; - int type; +inet6_rthdr_init(void *bp, int type) { struct cmsghdr *ch; struct ip6_rthdr *rthdr; @@ -114,10 +111,7 @@ inet6_rthdr_init(bp, type) } int -inet6_rthdr_add(cmsg, addr, flags) - struct cmsghdr *cmsg; - const struct in6_addr *addr; - u_int flags; +inet6_rthdr_add(struct cmsghdr *cmsg, const struct in6_addr *addr, u_int flags) { struct ip6_rthdr *rthdr; @@ -129,6 +123,7 @@ inet6_rthdr_add(cmsg, addr, flags) switch (rthdr->ip6r_type) { case IPV6_RTHDR_TYPE_0: { + size_t len; struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)(void *)rthdr; if (flags != IPV6_RTHDR_LOOSE && flags != IPV6_RTHDR_STRICT) return (-1); @@ -140,7 +135,9 @@ inet6_rthdr_add(cmsg, addr, flags) (void)memcpy(((caddr_t)(void *)rt0) + ((rt0->ip6r0_len + 1) << 3), addr, sizeof(struct in6_addr)); rt0->ip6r0_len += sizeof(struct in6_addr) >> 3; - cmsg->cmsg_len = CMSG_LEN((rt0->ip6r0_len + 1) << 3); + len = CMSG_LEN((rt0->ip6r0_len + 1) << 3); + _DIAGASSERT(__type_fit(socklen_t, len)); + cmsg->cmsg_len = (socklen_t)len; break; } default: @@ -151,9 +148,7 @@ inet6_rthdr_add(cmsg, addr, flags) } int -inet6_rthdr_lasthop(cmsg, flags) - struct cmsghdr *cmsg; - unsigned int flags; +inet6_rthdr_lasthop(struct cmsghdr *cmsg, unsigned int flags) { struct ip6_rthdr *rthdr; @@ -180,9 +175,7 @@ inet6_rthdr_lasthop(cmsg, flags) #if 0 int -inet6_rthdr_reverse(in, out) - const struct cmsghdr *in; - struct cmsghdr *out; +inet6_rthdr_reverse(const struct cmsghdr *in, struct cmsghdr *out) { return (-1); @@ -190,8 +183,7 @@ inet6_rthdr_reverse(in, out) #endif int -inet6_rthdr_segments(cmsg) - const struct cmsghdr *cmsg; +inet6_rthdr_segments(const struct cmsghdr *cmsg) { const struct ip6_rthdr *rthdr; @@ -204,11 +196,14 @@ inet6_rthdr_segments(cmsg) { const struct ip6_rthdr0 *rt0 = (const struct ip6_rthdr0 *)(const void *)rthdr; + size_t len; if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) return (-1); - return (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + len = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + _DIAGASSERT(__type_fit(int, len)); + return (int)len; } default: @@ -217,9 +212,7 @@ inet6_rthdr_segments(cmsg) } struct in6_addr * -inet6_rthdr_getaddr(cmsg, idx) - struct cmsghdr *cmsg; - int idx; +inet6_rthdr_getaddr(struct cmsghdr *cmsg, int idx) { struct ip6_rthdr *rthdr; @@ -232,10 +225,13 @@ inet6_rthdr_getaddr(cmsg, idx) { struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)(void *)rthdr; int naddr; + size_t len; if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) return NULL; - naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + len = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + _DIAGASSERT(__type_fit(int, len)); + naddr = (int)len; if (idx <= 0 || naddr < idx) return NULL; #ifdef COMPAT_RFC2292 @@ -251,9 +247,7 @@ inet6_rthdr_getaddr(cmsg, idx) } int -inet6_rthdr_getflags(cmsg, idx) - const struct cmsghdr *cmsg; - int idx; +inet6_rthdr_getflags(const struct cmsghdr *cmsg, int idx) { const struct ip6_rthdr *rthdr; @@ -267,10 +261,13 @@ inet6_rthdr_getflags(cmsg, idx) const struct ip6_rthdr0 *rt0 = (const struct ip6_rthdr0 *) (const void *)rthdr; int naddr; + size_t len; if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) return (-1); - naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + len = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + _DIAGASSERT(__type_fit(int, len)); + naddr = (int)len; if (idx < 0 || naddr < idx) return (-1); return IPV6_RTHDR_LOOSE; Index: quad/fixunsdfdi.c =================================================================== RCS file: /cvsroot/src/lib/libc/quad/fixunsdfdi.c,v retrieving revision 1.8 diff -u -p -u -r1.8 fixunsdfdi.c --- quad/fixunsdfdi.c 4 Jul 2011 06:23:50 -0000 1.8 +++ quad/fixunsdfdi.c 11 Mar 2012 15:11:35 -0000 @@ -44,7 +44,7 @@ __RCSID("$NetBSD: fixunsdfdi.c,v 1.8 201 #include "quad.h" -#define ONE_FOURTH ((int)1 << (INT_BITS - 2)) +#define ONE_FOURTH ((int)1 << (unsigned int)(INT_BITS - 2)) #define ONE_HALF (ONE_FOURTH * 2.0) #define ONE (ONE_FOURTH * 4.0) Index: quad/fixunssfdi.c =================================================================== RCS file: /cvsroot/src/lib/libc/quad/fixunssfdi.c,v retrieving revision 1.6 diff -u -p -u -r1.6 fixunssfdi.c --- quad/fixunssfdi.c 7 Aug 2003 16:43:16 -0000 1.6 +++ quad/fixunssfdi.c 11 Mar 2012 15:11:35 -0000 @@ -44,7 +44,7 @@ __RCSID("$NetBSD: fixunssfdi.c,v 1.6 200 #include "quad.h" -#define ONE_FOURTH ((int)1 << (INT_BITS - 2)) +#define ONE_FOURTH ((int)1 << (unsigned int)(INT_BITS - 2)) #define ONE_HALF (ONE_FOURTH * 2.0) #define ONE (ONE_FOURTH * 4.0) Index: quad/floatdidf.c =================================================================== RCS file: /cvsroot/src/lib/libc/quad/floatdidf.c,v retrieving revision 1.7 diff -u -p -u -r1.7 floatdidf.c --- quad/floatdidf.c 4 Jul 2011 06:23:50 -0000 1.7 +++ quad/floatdidf.c 11 Mar 2012 15:11:35 -0000 @@ -69,7 +69,7 @@ __floatdidf(quad_t x) * code and does not know how to get at an exponent. Machine- * specific code may be able to do this more efficiently. */ - d = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); + d = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); d += u.ul[L]; return (neg ? -d : d); Index: quad/floatdisf.c =================================================================== RCS file: /cvsroot/src/lib/libc/quad/floatdisf.c,v retrieving revision 1.7 diff -u -p -u -r1.7 floatdisf.c --- quad/floatdisf.c 4 Jul 2011 06:23:50 -0000 1.7 +++ quad/floatdisf.c 11 Mar 2012 15:11:35 -0000 @@ -71,7 +71,7 @@ __floatdisf(quad_t x) * * Using double here may be excessive paranoia. */ - f = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); + f = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); f += u.ul[L]; return (neg ? -f : f); Index: quad/floatundidf.c =================================================================== RCS file: /cvsroot/src/lib/libc/quad/floatundidf.c,v retrieving revision 1.1 diff -u -p -u -r1.1 floatundidf.c --- quad/floatundidf.c 4 Jul 2011 06:23:50 -0000 1.1 +++ quad/floatundidf.c 11 Mar 2012 15:11:35 -0000 @@ -55,7 +55,7 @@ __floatundidf(u_quad_t x) union uu u; u.uq = x; - d = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); + d = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); d += u.ul[L]; return (d); } Index: quad/floatundisf.c =================================================================== RCS file: /cvsroot/src/lib/libc/quad/floatundisf.c,v retrieving revision 1.1 diff -u -p -u -r1.1 floatundisf.c --- quad/floatundisf.c 4 Jul 2011 11:22:39 -0000 1.1 +++ quad/floatundisf.c 11 Mar 2012 15:11:35 -0000 @@ -64,7 +64,7 @@ __floatundisf(u_quad_t x) * * Using double here may be excessive paranoia. */ - f = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); + f = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); f += u.ul[L]; return f; Index: regex/engine.c =================================================================== RCS file: /cvsroot/src/lib/libc/regex/engine.c,v retrieving revision 1.23 diff -u -p -u -r1.23 engine.c --- regex/engine.c 9 Oct 2011 18:23:00 -0000 1.23 +++ regex/engine.c 11 Mar 2012 15:11:35 -0000 @@ -783,7 +783,7 @@ fast( int c = (start == m->beginp) ? OUT : *(start-1); int lastc; /* previous c */ int flagch; - int i; + size_t i; const char *coldp; /* last p after which no match was underway */ _DIAGASSERT(m != NULL); @@ -878,7 +878,7 @@ slow( int c = (start == m->beginp) ? OUT : *(start-1); int lastc; /* previous c */ int flagch; - int i; + size_t i; const char *matchp; /* last p at which a match ended */ _DIAGASSERT(m != NULL); Index: regex/regcomp.c =================================================================== RCS file: /cvsroot/src/lib/libc/regex/regcomp.c,v retrieving revision 1.32 diff -u -p -u -r1.32 regcomp.c --- regex/regcomp.c 8 Nov 2011 19:25:45 -0000 1.32 +++ regex/regcomp.c 11 Mar 2012 15:11:36 -0000 @@ -112,7 +112,7 @@ struct parse { sop *strip; /* malloced strip */ sopno ssize; /* malloced strip size (allocated) */ sopno slen; /* malloced strip length (used) */ - int ncsalloc; /* number of csets allocated */ + size_t ncsalloc; /* number of csets allocated */ struct re_guts *g; # define NPAREN 10 /* we need to remember () 1-9 for back refs */ sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ @@ -797,12 +797,12 @@ p_bracket( return; if (p->g->cflags®_ICASE) { - int i; + ssize_t i; int ci; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i) && isalpha(i)) { - ci = othercase(i); + ci = othercase((int)i); if (ci != i) CHadd(cs, ci); } @@ -810,13 +810,13 @@ p_bracket( mccase(p, cs); } if (invert) { - int i; + ssize_t i; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i)) - CHsub(cs, i); + CHsub(cs, (int)i); else - CHadd(cs, i); + CHadd(cs, (int)i); if (p->g->cflags®_NEWLINE) CHsub(cs, '\n'); if (cs->multis != NULL) @@ -1084,8 +1084,11 @@ ordinary( bothcases(p, (unsigned char) ch); else { EMIT(OCHAR, (sopno)(unsigned char)ch); - if (cap[ch] == 0) - cap[ch] = p->g->ncategories++; + if (cap[ch] == 0) { + _DIAGASSERT(__type_fit(unsigned char, + p->g->ncategories + 1)); + cap[ch] = (unsigned char)p->g->ncategories++; + } } } @@ -1227,12 +1230,12 @@ static cset * allocset( struct parse *p) { - int no; + size_t no; size_t nc; size_t nbytes; cset *cs; size_t css; - int i; + size_t i; _DIAGASSERT(p != NULL); @@ -1271,7 +1274,7 @@ oomem: cs = &p->g->sets[no]; cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); - cs->mask = 1 << ((no) % CHAR_BIT); + cs->mask = 1 << (unsigned int)((no) % CHAR_BIT); cs->hash = 0; cs->smultis = 0; cs->multis = NULL; @@ -1299,7 +1302,7 @@ freeset( css = (size_t)p->g->csetsize; for (i = 0; i < css; i++) - CHsub(cs, i); + CHsub(cs, (int)i); if (cs == top-1) /* recover only the easy case */ p->g->ncsets--; } @@ -1555,8 +1558,8 @@ isinsets( int c) { uch *col; - int i; - int ncols; + size_t i; + size_t ncols; unsigned uc = (unsigned char)c; _DIAGASSERT(g != NULL); @@ -1583,8 +1586,8 @@ samesets( int c2) { uch *col; - int i; - int ncols; + size_t i; + size_t ncols; unsigned uc1 = (unsigned char)c1; unsigned uc2 = (unsigned char)c2; @@ -1623,6 +1626,8 @@ categorize( for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (cats[c] == 0 && isinsets(g, c)) { + _DIAGASSERT(__type_fit(unsigned char, + g->ncategories + 1)); cat = g->ncategories++; cats[c] = cat; for (c2 = c+1; c2 <= CHAR_MAX; c2++) @@ -1673,7 +1678,6 @@ doemit( sop op, sopno opnd) { - _DIAGASSERT(p != NULL); /* avoid making error situations worse */ @@ -1689,7 +1693,7 @@ doemit( return; /* finally, it's all reduced to the easy case */ - p->strip[p->slen++] = SOP(op, opnd); + p->strip[p->slen++] = (sop)SOP(op, opnd); } /* @@ -1751,7 +1755,7 @@ dofwd( return; assert(value < 1<<OPSHIFT); - p->strip[pos] = OP(p->strip[pos]) | value; + p->strip[pos] = (sop)(OP(p->strip[pos]) | value); } /* Index: regex/regexec.c =================================================================== RCS file: /cvsroot/src/lib/libc/regex/regexec.c,v retrieving revision 1.21 diff -u -p -u -r1.21 regexec.c --- regex/regexec.c 12 Feb 2009 05:06:54 -0000 1.21 +++ regex/regexec.c 11 Mar 2012 15:11:36 -0000 @@ -171,7 +171,7 @@ __weak_alias(regexec,_regexec) #define STATETEARDOWN(m) { free((m)->space); m->space = NULL; } #define SETUP(v) ((v) = &m->space[(size_t)(m->vn++ * m->g->nstates)]) #define onestate int -#define INIT(o, n) ((o) = (n)) +#define INIT(o, n) ((o) = (int)(n)) #define INC(o) ((o)++) #define ISSTATEIN(v, o) ((v)[o]) /* some abbreviations; note that some of these know variable names! */ Index: resolv/herror.c =================================================================== RCS file: /cvsroot/src/lib/libc/resolv/herror.c,v retrieving revision 1.8 diff -u -p -u -r1.8 herror.c --- resolv/herror.c 12 Apr 2009 17:07:17 -0000 1.8 +++ resolv/herror.c 11 Mar 2012 15:11:36 -0000 @@ -121,7 +121,7 @@ herror(const char *s) { DE_CONST("\n", t); v->iov_base = t; v->iov_len = 1; - writev(STDERR_FILENO, iov, (v - iov) + 1); + (void)writev(STDERR_FILENO, iov, (int)((v - iov) + 1)); } /*% Index: resolv/res_comp.c =================================================================== RCS file: /cvsroot/src/lib/libc/resolv/res_comp.c,v retrieving revision 1.11 diff -u -p -u -r1.11 res_comp.c --- resolv/res_comp.c 17 Aug 2011 09:53:53 -0000 1.11 +++ resolv/res_comp.c 11 Mar 2012 15:11:36 -0000 @@ -86,6 +86,7 @@ __RCSID("$NetBSD: res_comp.c,v 1.11 2011 #include <sys/param.h> #include <netinet/in.h> #include <arpa/nameser.h> +#include <assert.h> #include <ctype.h> #include <resolv.h> #include <stdio.h> @@ -148,7 +149,8 @@ dn_skipname(const u_char *ptr, const u_c if (ns_name_skip(&ptr, eom) == -1) return (-1); - return (ptr - saveptr); + _DIAGASSERT(__type_fit(int, ptr - saveptr)); + return (int)(ptr - saveptr); } /*% Index: resolv/res_debug.c =================================================================== RCS file: /cvsroot/src/lib/libc/resolv/res_debug.c,v retrieving revision 1.11 diff -u -p -u -r1.11 res_debug.c --- resolv/res_debug.c 12 Apr 2009 17:07:17 -0000 1.11 +++ resolv/res_debug.c 11 Mar 2012 15:11:36 -0000 @@ -116,6 +116,7 @@ __RCSID("$NetBSD: res_debug.c,v 1.11 200 #include <arpa/inet.h> #include <arpa/nameser.h> +#include <assert.h> #include <ctype.h> #include <errno.h> #include <math.h> @@ -176,7 +177,7 @@ do_section(const res_state statp, /* * Print answer records. */ - sflag = (statp->pfcode & pflag); + sflag = (int)(statp->pfcode & pflag); if (statp->pfcode && !sflag) return; @@ -207,11 +208,14 @@ do_section(const res_state statp, p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr))); else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) { - u_int16_t optcode, optlen, rdatalen = ns_rr_rdlen(rr); - u_int32_t ttl = ns_rr_ttl(rr); + size_t rdatalen, ttl; + uint16_t optcode, optlen; + + rdatalen = ns_rr_rdlen(rr); + ttl = ns_rr_ttl(rr); fprintf(file, - "; EDNS: version: %u, udp=%u, flags=%04x\n", + "; EDNS: version: %zu, udp=%u, flags=%04zx\n", (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff); while (rdatalen >= 4) { @@ -368,7 +372,7 @@ p_cdnname(const u_char *cp, const u_char char name[MAXDNAME]; int n; - if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0) + if ((n = dn_expand(msg, msg + len, cp, name, (int)sizeof name)) < 0) return (NULL); if (name[0] == '\0') putc('.', file); @@ -393,13 +397,14 @@ p_fqnname(cp, msg, msglen, name, namelen char *name; int namelen; { - int n, newlen; + int n; + size_t newlen; if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0) return (NULL); newlen = strlen(name); if (newlen == 0 || name[newlen - 1] != '.') { - if (newlen + 1 >= namelen) /*%< Lack space for final dot */ + if ((int)newlen + 1 >= namelen) /*%< Lack space for final dot */ return (NULL); else strcpy(name + newlen, "."); @@ -414,7 +419,7 @@ p_fqname(const u_char *cp, const u_char char name[MAXDNAME]; const u_char *n; - n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name); + n = p_fqnname(cp, msg, MAXCDNAME, name, (int)sizeof name); if (n == NULL) return (NULL); fputs(name, file); @@ -749,7 +754,7 @@ p_sockun(union res_sockaddr_union u, cha switch (u.sin.sin_family) { case AF_INET: - inet_ntop(AF_INET, &u.sin.sin_addr, ret, sizeof ret); + inet_ntop(AF_INET, &u.sin.sin_addr, ret, (socklen_t)sizeof ret); break; #ifdef HAS_INET6_STRUCTS case AF_INET6: @@ -1153,7 +1158,7 @@ loc_ntoa(binary, ascii) /*% Return the number of DNS hierarchy levels in the name. */ int dn_count_labels(const char *name) { - int i, len, count; + size_t len, i, count; len = strlen(name); for (i = 0, count = 0; i < len; i++) { @@ -1172,7 +1177,8 @@ dn_count_labels(const char *name) { /* count to include last label */ if (len > 0 && name[len-1] != '.') count++; - return (count); + _DIAGASSERT(__type_fit(int, count)); + return (int)count; } /*% Index: resolv/res_debug.h =================================================================== RCS file: /cvsroot/src/lib/libc/resolv/res_debug.h,v retrieving revision 1.1.1.4 diff -u -p -u -r1.1.1.4 res_debug.h --- resolv/res_debug.h 12 Apr 2009 16:35:47 -0000 1.1.1.4 +++ resolv/res_debug.h 11 Mar 2012 15:11:36 -0000 @@ -29,7 +29,7 @@ # define Dprint(cond, args) if (cond) {fprintf args;} else {} # define DprintQ(cond, args, query, size) if (cond) {\ fprintf args;\ - res_pquery(statp, query, size, stdout);\ + res_pquery(statp, (query), (int)(size), stdout);\ } else {} #endif Index: resolv/res_init.c =================================================================== RCS file: /cvsroot/src/lib/libc/resolv/res_init.c,v retrieving revision 1.23 diff -u -p -u -r1.23 res_init.c --- resolv/res_init.c 15 Oct 2011 23:00:02 -0000 1.23 +++ resolv/res_init.c 11 Mar 2012 15:11:37 -0000 @@ -351,7 +351,7 @@ __res_vinit(res_state statp, int preinit struct kevent kc; /* read the config file */ - while (fgets(buf, sizeof(buf), fp) != NULL) { + while (fgets(buf, (int)sizeof(buf), fp) != NULL) { /* skip comments */ if (*buf == ';' || *buf == '#') continue; @@ -598,6 +598,7 @@ res_setoptions(res_state statp, const ch { const char *cp = options; int i; + size_t j; struct __res_state_ext *ext = statp->_u._ext.ext; #ifdef DEBUG @@ -690,17 +691,17 @@ res_setoptions(res_state statp, const ch if (ext == NULL) goto skip; cp += sizeof("nibble:") - 1; - i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1); - strncpy(ext->nsuffix, cp, (size_t)i); - ext->nsuffix[i] = '\0'; + j = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1); + strncpy(ext->nsuffix, cp, j); + ext->nsuffix[j] = '\0'; } else if (!strncmp(cp, "nibble2:", sizeof("nibble2:") - 1)) { if (ext == NULL) goto skip; cp += sizeof("nibble2:") - 1; - i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1); - strncpy(ext->nsuffix2, cp, (size_t)i); - ext->nsuffix2[i] = '\0'; + j = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1); + strncpy(ext->nsuffix2, cp, j); + ext->nsuffix2[j] = '\0'; } else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) { cp += sizeof("v6revmode:") - 1; Index: resolv/res_mkquery.c =================================================================== RCS file: /cvsroot/src/lib/libc/resolv/res_mkquery.c,v retrieving revision 1.12 diff -u -p -u -r1.12 res_mkquery.c --- resolv/res_mkquery.c 12 Apr 2009 19:43:37 -0000 1.12 +++ resolv/res_mkquery.c 11 Mar 2012 15:11:37 -0000 @@ -87,6 +87,7 @@ __RCSID("$NetBSD: res_mkquery.c,v 1.12 2 #include <sys/param.h> #include <netinet/in.h> #include <arpa/nameser.h> +#include <assert.h> #include <netdb.h> #include <resolv.h> #include <stdio.h> @@ -160,7 +161,7 @@ res_nmkquery(res_state statp, case NS_NOTIFY_OP: if (ep - cp < QFIXEDSZ) return (-1); - if ((n = dn_comp(dname, cp, ep - cp - QFIXEDSZ, dnptrs, + if ((n = dn_comp(dname, cp, (int)(ep - cp - QFIXEDSZ), dnptrs, lastdnptr)) < 0) return (-1); cp += n; @@ -176,7 +177,7 @@ res_nmkquery(res_state statp, */ if ((ep - cp) < RRFIXEDSZ) return (-1); - n = dn_comp((const char *)data, cp, ep - cp - RRFIXEDSZ, + n = dn_comp((const char *)data, cp, (int)(ep - cp - RRFIXEDSZ), dnptrs, lastdnptr); if (n < 0) return (-1); @@ -217,7 +218,8 @@ res_nmkquery(res_state statp, default: return (-1); } - return (cp - buf); + _DIAGASSERT(__type_fit(int, cp - buf)); + return (int)(cp - buf); } #ifdef RES_USE_EDNS0 @@ -269,7 +271,8 @@ res_nopt(res_state statp, hp->arcount = htons(ntohs(hp->arcount) + 1); - return (cp - buf); + _DIAGASSERT(__type_fit(int, cp - buf)); + return (int)(cp - buf); } /* @@ -312,10 +315,12 @@ res_nopt_rdata(res_state statp, memcpy(cp, data, (size_t)len); cp += len; - len = cp - rdata; + _DIAGASSERT(__type_fit(u_short, cp - rdata)); + len = (u_short)(cp - rdata); ns_put16(len, rdata - 2); /* Update RDLEN field */ - return (cp - buf); + _DIAGASSERT(__type_fit(int, cp - buf)); + return (int)(cp - buf); } #endif Index: resolv/res_query.c =================================================================== RCS file: /cvsroot/src/lib/libc/resolv/res_query.c,v retrieving revision 1.13 diff -u -p -u -r1.13 res_query.c --- resolv/res_query.c 24 Oct 2009 21:37:57 -0000 1.13 +++ resolv/res_query.c 11 Mar 2012 15:11:37 -0000 @@ -168,15 +168,15 @@ again: #endif n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL, - buf, sizeof(buf)); + buf, (int)sizeof(buf)); #ifdef RES_USE_EDNS0 if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 && (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC|RES_NSID)) != 0U) { - n = res_nopt(statp, n, buf, sizeof(buf), anslen); + n = res_nopt(statp, n, buf, (int)sizeof(buf), anslen); rdata = &buf[n]; if (n > 0 && (statp->options & RES_NSID) != 0U) { - n = res_nopt_rdata(statp, n, buf, sizeof(buf), rdata, - NS_OPT_NSID, 0, NULL); + n = res_nopt_rdata(statp, n, buf, (int)sizeof(buf), + rdata, NS_OPT_NSID, 0, NULL); } } #endif @@ -402,7 +402,7 @@ res_nquerydomain(res_state statp, { char nbuf[MAXDNAME]; const char *longname = nbuf; - int n, d; + size_t n, d; #ifdef DEBUG if (statp->options & RES_DEBUG) @@ -419,9 +419,8 @@ res_nquerydomain(res_state statp, RES_SET_H_ERRNO(statp, NO_RECOVERY); return (-1); } - n--; - if (n >= 0 && name[n] == '.') { - strncpy(nbuf, name, (size_t)n); + if (n && name[--n] == '.') { + strncpy(nbuf, name, n); nbuf[n] = '\0'; } else longname = name; @@ -455,7 +454,7 @@ res_hostalias(const res_state statp, con if (file == NULL || (fp = fopen(file, "r")) == NULL) return (NULL); buf[sizeof(buf) - 1] = '\0'; - while (fgets(buf, sizeof(buf), fp)) { + while (fgets(buf, (int)sizeof(buf), fp)) { for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1) ; if (!*cp1) Index: resolv/res_send.c =================================================================== RCS file: /cvsroot/src/lib/libc/resolv/res_send.c,v retrieving revision 1.22 diff -u -p -u -r1.22 res_send.c --- resolv/res_send.c 23 May 2011 14:34:29 -0000 1.22 +++ resolv/res_send.c 11 Mar 2012 15:11:37 -0000 @@ -116,6 +116,7 @@ __RCSID("$NetBSD: res_send.c,v 1.22 2011 #include <arpa/nameser.h> #include <arpa/inet.h> +#include <assert.h> #include <errno.h> #include <netdb.h> #include <resolv.h> @@ -259,7 +260,7 @@ res_nameinquery(const char *name, int ty char tname[MAXDNAME+1]; int n, ttype, tclass; - n = dn_expand(buf, eom, cp, tname, sizeof tname); + n = dn_expand(buf, eom, cp, tname, (int)sizeof tname); if (n < 0) return (-1); cp += n; @@ -310,7 +311,7 @@ res_queriesmatch(const u_char *buf1, con char tname[MAXDNAME+1]; int n, ttype, tclass; - n = dn_expand(buf1, eom1, cp, tname, sizeof tname); + n = dn_expand(buf1, eom1, cp, tname, (int)sizeof tname); if (n < 0) return (-1); cp += n; @@ -478,8 +479,8 @@ res_nsend(res_state statp, } Dprint(((statp->options & RES_DEBUG) && - getnameinfo(nsap, (socklen_t)nsaplen, abuf, sizeof(abuf), - NULL, 0, niflags) == 0), + getnameinfo(nsap, (socklen_t)nsaplen, abuf, + (socklen_t)sizeof(abuf), NULL, 0, niflags) == 0), (stdout, ";; Querying server (# %d) address = %s\n", ns + 1, abuf)); @@ -629,7 +630,8 @@ send_vc(res_state statp, HEADER *anhp = (HEADER *)(void *)ans; struct sockaddr *nsap; int nsaplen; - int truncating, connreset, resplen, n; + int truncating, connreset, resplen; + ssize_t n; struct iovec iov[2]; u_short len; u_char *cp; @@ -693,7 +695,7 @@ send_vc(res_state statp, * Push on even if setsockopt(SO_NOSIGPIPE) fails. */ (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on, - sizeof(on)); + (unsigned int)sizeof(on)); #endif errno = 0; if (connect(statp->_vcsock, nsap, (socklen_t)nsaplen) < 0) { @@ -727,7 +729,7 @@ send_vc(res_state statp, len = INT16SZ; while ((n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0) { cp += n; - if ((len -= n) == 0) + if ((len -= (u_short)n) == 0) break; } if (n <= 0) { @@ -773,7 +775,7 @@ send_vc(res_state statp, cp = ans; while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0){ cp += n; - len -= n; + len -= (u_short)n; } if (n <= 0) { *terrno = errno; @@ -793,7 +795,7 @@ send_vc(res_state statp, n = read(statp->_vcsock, junk, (len > sizeof junk) ? sizeof junk : len); if (n > 0) - len -= n; + len -= (u_short)n; else break; } @@ -832,7 +834,8 @@ send_dg(res_state statp, const u_char *b struct timespec now, timeout, finish; struct sockaddr_storage from; ISC_SOCKLEN_T fromlen; - int resplen, seconds, n, s; + ssize_t resplen; + int seconds, n, s; #ifdef USE_POLL int polltimeout; struct pollfd pollfd; @@ -968,7 +971,7 @@ send_dg(res_state statp, const u_char *b * Undersized message. */ Dprint(statp->options & RES_DEBUG, - (stdout, ";; undersized: %d\n", + (stdout, ";; undersized: %zd\n", resplen)); *terrno = EMSGSIZE; res_nclose(statp); @@ -1026,7 +1029,7 @@ send_dg(res_state statp, const u_char *b DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY), (stdout, ";; wrong query name:\n"), - ans, (resplen > anssiz) ? anssiz : resplen); + ans, (int)(resplen > anssiz) ? anssiz : resplen); goto wait; } if (anhp->rcode == SERVFAIL || @@ -1034,7 +1037,7 @@ send_dg(res_state statp, const u_char *b anhp->rcode == REFUSED) { DprintQ(statp->options & RES_DEBUG, (stdout, "server rejected query:\n"), - ans, (resplen > anssiz) ? anssiz : resplen); + ans, (int)(resplen > anssiz) ? anssiz : resplen); res_nclose(statp); /* don't retry if called from dig */ if (!statp->pfcode) @@ -1055,7 +1058,8 @@ send_dg(res_state statp, const u_char *b * All is well, or the error is fatal. Signal that the * next nameserver ought not be tried. */ - return (resplen); + _DIAGASSERT(__type_fit(int, resplen)); + return (int)resplen; } static void @@ -1067,8 +1071,9 @@ Aerror(const res_state statp, FILE *file char sbuf[NI_MAXSERV]; if ((statp->options & RES_DEBUG) != 0U) { - if (getnameinfo(address, (socklen_t)alen, hbuf, sizeof(hbuf), - sbuf, sizeof(sbuf), niflags)) { + if (getnameinfo(address, (socklen_t)alen, hbuf, + (socklen_t)sizeof(hbuf), sbuf, (socklen_t)sizeof(sbuf), + niflags)) { strncpy(hbuf, "?", sizeof(hbuf) - 1); hbuf[sizeof(hbuf) - 1] = '\0'; strncpy(sbuf, "?", sizeof(sbuf) - 1); Index: rpc/authunix_prot.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/authunix_prot.c,v retrieving revision 1.13 diff -u -p -u -r1.13 authunix_prot.c --- rpc/authunix_prot.c 11 May 2006 17:11:57 -0000 1.13 +++ rpc/authunix_prot.c 11 Mar 2012 15:11:37 -0000 @@ -76,7 +76,8 @@ xdr_authunix_parms(xdrs, p) && xdr_int(xdrs, &(p->aup_uid)) && xdr_int(xdrs, &(p->aup_gid)) && xdr_array(xdrs, (char **)(void *)&(p->aup_gids), - &(p->aup_len), NGRPS, sizeof(int), (xdrproc_t)xdr_int) ) { + &(p->aup_len), NGRPS, (unsigned int)sizeof(int), + (xdrproc_t)xdr_int) ) { return (TRUE); } return (FALSE); Index: rpc/bindresvport.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/bindresvport.c,v retrieving revision 1.21 diff -u -p -u -r1.21 bindresvport.c --- rpc/bindresvport.c 18 Jan 2003 11:29:03 -0000 1.21 +++ rpc/bindresvport.c 11 Mar 2012 15:11:37 -0000 @@ -136,7 +136,7 @@ bindresvport_sa(sd, sa) if (error < 0) return (error); error = setsockopt(sd, proto, portrange, &portlow, - sizeof(portlow)); + (socklen_t)sizeof(portlow)); if (error < 0) return (error); } @@ -148,7 +148,7 @@ bindresvport_sa(sd, sa) if (error < 0) { if (setsockopt(sd, proto, portrange, &old, - sizeof(old)) < 0) + (socklen_t)sizeof(old)) < 0) errno = saved_errno; return (error); } Index: rpc/clnt_bcast.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/clnt_bcast.c,v retrieving revision 1.22 diff -u -p -u -r1.22 clnt_bcast.c --- rpc/clnt_bcast.c 7 Mar 2010 23:49:14 -0000 1.22 +++ rpc/clnt_bcast.c 11 Mar 2012 15:11:37 -0000 @@ -234,7 +234,8 @@ __rpc_broadenable(int af, int s, struct return -1; } else #endif - if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) < 0) + if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, + (socklen_t)sizeof(o)) == -1) return -1; return 0; @@ -282,7 +283,7 @@ rpc_broadcast_exp(prog, vers, proc, xarg broadlist_t nal; } fdlist[MAXBCAST]; struct pollfd pfd[MAXBCAST]; - size_t fdlistno = 0; + nfds_t fdlistno = 0; struct r_rpcb_rmtcallargs barg; /* Remote arguments */ struct r_rpcb_rmtcallres bres; /* Remote results */ size_t outlen; @@ -469,7 +470,7 @@ rpc_broadcast_exp(prog, vers, proc, xarg if (!__rpc_lowvers) if ((size_t)sendto(fdlist[i].fd, outbuf, outlen, 0, (struct sockaddr*)addr, - (size_t)fdlist[i].asize) != + (socklen_t)fdlist[i].asize) != outlen) { warn("clnt_bcast: cannot send" " broadcast packet"); @@ -491,7 +492,7 @@ rpc_broadcast_exp(prog, vers, proc, xarg fdlist[i].proto == IPPROTO_UDP) { if ((size_t)sendto(fdlist[i].fd, outbuf_pmap, outlen_pmap, 0, addr, - (size_t)fdlist[i].asize) != + (socklen_t)fdlist[i].asize) != outlen_pmap) { warnx("clnt_bcast: " "Cannot send " Index: rpc/clnt_vc.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/clnt_vc.c,v retrieving revision 1.17 diff -u -p -u -r1.17 clnt_vc.c --- rpc/clnt_vc.c 8 Dec 2010 02:06:38 -0000 1.17 +++ rpc/clnt_vc.c 11 Mar 2012 15:11:38 -0000 @@ -85,17 +85,17 @@ __weak_alias(clnt_vc_create,_clnt_vc_cre #define MCALL_MSG_SIZE 24 -static enum clnt_stat clnt_vc_call __P((CLIENT *, rpcproc_t, xdrproc_t, - const char *, xdrproc_t, caddr_t, struct timeval)); -static void clnt_vc_geterr __P((CLIENT *, struct rpc_err *)); -static bool_t clnt_vc_freeres __P((CLIENT *, xdrproc_t, caddr_t)); -static void clnt_vc_abort __P((CLIENT *)); -static bool_t clnt_vc_control __P((CLIENT *, u_int, char *)); -static void clnt_vc_destroy __P((CLIENT *)); -static struct clnt_ops *clnt_vc_ops __P((void)); -static bool_t time_not_ok __P((struct timeval *)); -static int read_vc __P((caddr_t, caddr_t, int)); -static int write_vc __P((caddr_t, caddr_t, int)); +static enum clnt_stat clnt_vc_call(CLIENT *, rpcproc_t, xdrproc_t, + const char *, xdrproc_t, caddr_t, struct timeval); +static void clnt_vc_geterr(CLIENT *, struct rpc_err *); +static bool_t clnt_vc_freeres(CLIENT *, xdrproc_t, caddr_t); +static void clnt_vc_abort(CLIENT *); +static bool_t clnt_vc_control(CLIENT *, u_int, char *); +static void clnt_vc_destroy(CLIENT *); +static struct clnt_ops *clnt_vc_ops(void); +static bool_t time_not_ok(struct timeval *); +static int read_vc(caddr_t, caddr_t, int); +static int write_vc(caddr_t, caddr_t, int); struct ct_data { int ct_fd; @@ -154,13 +154,14 @@ static cond_t *vc_cv; * fd should be an open socket */ CLIENT * -clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz) - int fd; - const struct netbuf *raddr; - rpcprog_t prog; - rpcvers_t vers; - u_int sendsz; - u_int recvsz; +clnt_vc_create( + int fd, + const struct netbuf *raddr, + rpcprog_t prog, + rpcvers_t vers, + u_int sendsz, + u_int recvsz +) { CLIENT *h; struct ct_data *ct = NULL; @@ -314,14 +315,15 @@ fooy: } static enum clnt_stat -clnt_vc_call(h, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout) - CLIENT *h; - rpcproc_t proc; - xdrproc_t xdr_args; - const char *args_ptr; - xdrproc_t xdr_results; - caddr_t results_ptr; - struct timeval timeout; +clnt_vc_call( + CLIENT *h, + rpcproc_t proc, + xdrproc_t xdr_args, + const char *args_ptr, + xdrproc_t xdr_results, + caddr_t results_ptr, + struct timeval timeout +) { struct ct_data *ct; XDR *xdrs; @@ -444,9 +446,10 @@ call_again: } static void -clnt_vc_geterr(h, errp) - CLIENT *h; - struct rpc_err *errp; +clnt_vc_geterr( + CLIENT *h, + struct rpc_err *errp +) { struct ct_data *ct; @@ -458,10 +461,11 @@ clnt_vc_geterr(h, errp) } static bool_t -clnt_vc_freeres(cl, xdr_res, res_ptr) - CLIENT *cl; - xdrproc_t xdr_res; - caddr_t res_ptr; +clnt_vc_freeres( + CLIENT *cl, + xdrproc_t xdr_res, + caddr_t res_ptr +) { struct ct_data *ct; XDR *xdrs; @@ -495,16 +499,16 @@ clnt_vc_freeres(cl, xdr_res, res_ptr) /*ARGSUSED*/ static void -clnt_vc_abort(cl) - CLIENT *cl; +clnt_vc_abort(CLIENT *cl) { } static bool_t -clnt_vc_control(cl, request, info) - CLIENT *cl; - u_int request; - char *info; +clnt_vc_control( + CLIENT *cl, + u_int request, + char *info +) { struct ct_data *ct; void *infop = info; @@ -631,8 +635,7 @@ clnt_vc_control(cl, request, info) static void -clnt_vc_destroy(cl) - CLIENT *cl; +clnt_vc_destroy(CLIENT *cl) { struct ct_data *ct; #ifdef _REENTRANT @@ -673,14 +676,12 @@ clnt_vc_destroy(cl) * around for the rpc level. */ static int -read_vc(ctp, buf, len) - caddr_t ctp; - caddr_t buf; - int len; +read_vc(char *ctp, char *buf, int len) { struct ct_data *ct = (struct ct_data *)(void *)ctp; struct pollfd fd; struct timespec ts; + ssize_t nread; if (len == 0) return (0); @@ -703,7 +704,7 @@ read_vc(ctp, buf, len) } break; } - switch (len = read(ct->ct_fd, buf, (size_t)len)) { + switch (nread = read(ct->ct_fd, buf, (size_t)len)) { case 0: /* premature eof */ @@ -717,30 +718,28 @@ read_vc(ctp, buf, len) ct->ct_error.re_status = RPC_CANTRECV; break; } - return (len); + return (int)nread; } static int -write_vc(ctp, buf, len) - caddr_t ctp; - caddr_t buf; - int len; +write_vc(char *ctp, char *buf, int len) { struct ct_data *ct = (struct ct_data *)(void *)ctp; - int i, cnt; + ssize_t i; + size_t cnt; for (cnt = len; cnt > 0; cnt -= i, buf += i) { - if ((i = write(ct->ct_fd, buf, (size_t)cnt)) == -1) { + if ((i = write(ct->ct_fd, buf, cnt)) == -1) { ct->ct_error.re_errno = errno; ct->ct_error.re_status = RPC_CANTSEND; return (-1); } } - return (len); + return len; } static struct clnt_ops * -clnt_vc_ops() +clnt_vc_ops(void) { static struct clnt_ops ops; #ifdef _REENTRANT @@ -772,8 +771,7 @@ clnt_vc_ops() * Note this is different from time_not_ok in clnt_dg.c */ static bool_t -time_not_ok(t) - struct timeval *t; +time_not_ok(struct timeval *t) { _DIAGASSERT(t != NULL); Index: rpc/pmap_rmt.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/pmap_rmt.c,v retrieving revision 1.30 diff -u -p -u -r1.30 pmap_rmt.c --- rpc/pmap_rmt.c 23 Mar 2010 20:28:59 -0000 1.30 +++ rpc/pmap_rmt.c 11 Mar 2012 15:11:38 -0000 @@ -175,7 +175,7 @@ xdr_rmtcallres(xdrs, crp) _DIAGASSERT(crp != NULL); port_ptr = (caddr_t)(void *)crp->port_ptr; - if (xdr_reference(xdrs, &port_ptr, sizeof (u_long), + if (xdr_reference(xdrs, &port_ptr, (u_int)sizeof(u_long), (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) { crp->port_ptr = (u_long *)(void *)port_ptr; return ((*(crp->xdr_results))(xdrs, crp->results_ptr)); Index: rpc/rpc_generic.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/rpc_generic.c,v retrieving revision 1.24 diff -u -p -u -r1.24 rpc_generic.c --- rpc/rpc_generic.c 8 Dec 2010 02:06:38 -0000 1.24 +++ rpc/rpc_generic.c 11 Mar 2012 15:11:38 -0000 @@ -649,8 +649,8 @@ __rpc_taddr2uaddr_af(int af, const struc switch (af) { case AF_INET: sinp = nbuf->buf; - if (inet_ntop(af, &sinp->sin_addr, namebuf, sizeof namebuf) - == NULL) + if (inet_ntop(af, &sinp->sin_addr, namebuf, + (socklen_t)sizeof namebuf) == NULL) return NULL; port = ntohs(sinp->sin_port); if (asprintf(&ret, "%s.%u.%u", namebuf, ((u_int32_t)port) >> 8, @@ -660,8 +660,8 @@ __rpc_taddr2uaddr_af(int af, const struc #ifdef INET6 case AF_INET6: sin6 = nbuf->buf; - if (inet_ntop(af, &sin6->sin6_addr, namebuf6, sizeof namebuf6) - == NULL) + if (inet_ntop(af, &sin6->sin6_addr, namebuf6, + (socklen_t)sizeof namebuf6) == NULL) return NULL; port = ntohs(sin6->sin6_port); if (asprintf(&ret, "%s.%u.%u", namebuf6, ((u_int32_t)port) >> 8, @@ -687,6 +687,7 @@ __rpc_uaddr2taddr_af(int af, const char struct netbuf *ret = NULL; char *addrstr, *p; unsigned port, portlo, porthi; + size_t len; struct sockaddr_in *sinp; #ifdef INET6 struct sockaddr_in6 *sin6; @@ -765,7 +766,9 @@ __rpc_uaddr2taddr_af(int af, const char memset(sun, 0, sizeof *sun); sun->sun_family = AF_LOCAL; strncpy(sun->sun_path, addrstr, sizeof(sun->sun_path) - 1); - ret->len = ret->maxlen = sun->sun_len = SUN_LEN(sun); + len = SUN_LEN(sun); + _DIAGASSERT(__type_fit(uint8_t, len)); + ret->len = ret->maxlen = sun->sun_len = (uint8_t)len; ret->buf = sun; break; default: @@ -893,5 +896,6 @@ __rpc_setnodelay(int fd, const struct __ int one = 1; if (si->si_proto != IPPROTO_TCP) return 0; - return setsockopt(fd, si->si_proto, TCP_NODELAY, &one, sizeof(one)); + return setsockopt(fd, si->si_proto, TCP_NODELAY, &one, + (socklen_t)sizeof(one)); } Index: rpc/rpc_prot.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/rpc_prot.c,v retrieving revision 1.18 diff -u -p -u -r1.18 rpc_prot.c --- rpc/rpc_prot.c 29 May 2003 18:15:25 -0000 1.18 +++ rpc/rpc_prot.c 11 Mar 2012 15:11:38 -0000 @@ -105,7 +105,8 @@ xdr_des_block(xdrs, blkp) _DIAGASSERT(xdrs != NULL); _DIAGASSERT(blkp != NULL); - return (xdr_opaque(xdrs, (caddr_t)(void *)blkp, sizeof(des_block))); + return (xdr_opaque(xdrs, (caddr_t)(void *)blkp, + (u_int)sizeof(des_block))); } /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */ Index: rpc/rpcb_clnt.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/rpcb_clnt.c,v retrieving revision 1.25 diff -u -p -u -r1.25 rpcb_clnt.c --- rpc/rpcb_clnt.c 23 Mar 2010 20:28:58 -0000 1.25 +++ rpc/rpcb_clnt.c 11 Mar 2012 15:11:38 -0000 @@ -466,13 +466,16 @@ local_rpcb() goto try_nconf; sun.sun_family = AF_LOCAL; strcpy(sun.sun_path, _PATH_RPCBINDSOCK); - nbuf.len = sun.sun_len = SUN_LEN(&sun); + tsize = SUN_LEN(&sun); + _DIAGASSERT(__type_fit(uint8_t, tsize)); + nbuf.len = sun.sun_len = (uint8_t)tsize; nbuf.maxlen = sizeof (struct sockaddr_un); nbuf.buf = &sun; tsize = __rpc_get_t_size(AF_LOCAL, 0, 0); + _DIAGASSERT(__type_fit(u_int, tsize)); client = clnt_vc_create(sock, &nbuf, (rpcprog_t)RPCBPROG, - (rpcvers_t)RPCBVERS, tsize, tsize); + (rpcvers_t)RPCBVERS, (u_int)tsize, (u_int)tsize); if (client != NULL) { /* XXX - mark the socket to be closed in destructor */ Index: rpc/rpcb_st_xdr.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/rpcb_st_xdr.c,v retrieving revision 1.7 diff -u -p -u -r1.7 rpcb_st_xdr.c --- rpc/rpcb_st_xdr.c 11 May 2006 17:11:57 -0000 1.7 +++ rpc/rpcb_st_xdr.c 11 Mar 2012 15:11:38 -0000 @@ -85,7 +85,7 @@ xdr_rpcbs_addrlist(xdrs, objp) } if (!xdr_pointer(xdrs, (char **)(void *)&objp->next, - sizeof (rpcbs_addrlist), + (u_int)sizeof (rpcbs_addrlist), (xdrproc_t)xdr_rpcbs_addrlist)) { return (FALSE); } @@ -138,7 +138,7 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) return (FALSE); } if (!xdr_pointer(xdrs, (char **)(void *)&objp->next, - sizeof (rpcbs_rmtcalllist), + (u_int)sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { return (FALSE); } @@ -176,7 +176,7 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) return (FALSE); } if (!xdr_pointer(xdrs, (char **)(void *)&objp->next, - sizeof (rpcbs_rmtcalllist), + (u_int)sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { return (FALSE); } @@ -204,7 +204,7 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) return (FALSE); } if (!xdr_pointer(xdrs, (char **)(void *)&objp->next, - sizeof (rpcbs_rmtcalllist), + (u_int)sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { return (FALSE); } @@ -217,7 +217,7 @@ xdr_rpcbs_proc(xdrs, objp) rpcbs_proc objp; { if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC, - sizeof (int), (xdrproc_t)xdr_int)) { + (u_int)sizeof (int), (xdrproc_t)xdr_int)) { return (FALSE); } return (TRUE); @@ -228,7 +228,7 @@ xdr_rpcbs_addrlist_ptr(xdrs, objp) XDR *xdrs; rpcbs_addrlist_ptr *objp; { - if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist), + if (!xdr_pointer(xdrs, (char **)objp, (u_int)sizeof (rpcbs_addrlist), (xdrproc_t)xdr_rpcbs_addrlist)) { return (FALSE); } @@ -240,7 +240,7 @@ xdr_rpcbs_rmtcalllist_ptr(xdrs, objp) XDR *xdrs; rpcbs_rmtcalllist_ptr *objp; { - if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist), + if (!xdr_pointer(xdrs, (char **)objp, (u_int)sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { return (FALSE); } @@ -280,7 +280,7 @@ xdr_rpcb_stat_byvers(xdrs, objp) rpcb_stat_byvers objp; { if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT, - sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) { + (u_int)sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) { return (FALSE); } return (TRUE); Index: rpc/svc_auth_unix.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/svc_auth_unix.c,v retrieving revision 1.18 diff -u -p -u -r1.18 svc_auth_unix.c --- rpc/svc_auth_unix.c 18 Jan 2003 11:29:06 -0000 1.18 +++ rpc/svc_auth_unix.c 11 Mar 2012 15:11:38 -0000 @@ -106,7 +106,8 @@ _svcauth_unix(rqst, msg) stat = AUTH_BADCRED; goto done; } - aup->aup_len = gid_len; + _DIAGASSERT(__type_fit(u_int, gid_len)); + aup->aup_len = (u_int)gid_len; for (i = 0; i < gid_len; i++) { aup->aup_gids[i] = (int)IXDR_GET_INT32(buf); } Index: rpc/svc_dg.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/svc_dg.c,v retrieving revision 1.12 diff -u -p -u -r1.12 svc_dg.c --- rpc/svc_dg.c 25 Apr 2008 17:44:44 -0000 1.12 +++ rpc/svc_dg.c 11 Mar 2012 15:11:39 -0000 @@ -140,7 +140,8 @@ svc_dg_create(fd, sendsize, recvsize) su->su_iosz = ((MAX(sendsize, recvsize) + 3) / 4) * 4; if ((rpc_buffer(xprt) = malloc(su->su_iosz)) == NULL) goto freedata; - xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz, + _DIAGASSERT(__type_fit(u_int, su->su_iosz)); + xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), (u_int)su->su_iosz, XDR_DECODE); su->su_cache = NULL; xprt->xp_fd = fd; @@ -566,8 +567,9 @@ cache_set(xprt, replylen) victim->cache_replylen = replylen; victim->cache_reply = rpc_buffer(xprt); rpc_buffer(xprt) = newbuf; - xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), - su->su_iosz, XDR_ENCODE); + _DIAGASSERT(__type_fit(u_int, su->su_iosz)); + xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), (u_int)su->su_iosz, + XDR_ENCODE); victim->cache_xid = su->su_xid; victim->cache_proc = uc->uc_proc; victim->cache_vers = uc->uc_vers; Index: rpc/svc_vc.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/svc_vc.c,v retrieving revision 1.24 diff -u -p -u -r1.24 svc_vc.c --- rpc/svc_vc.c 4 Feb 2011 17:38:15 -0000 1.24 +++ rpc/svc_vc.c 11 Mar 2012 15:11:39 -0000 @@ -175,7 +175,8 @@ svc_vc_create(int fd, u_int sendsize, u_ * We want to be able to check credentials on local sockets. */ if (sslocal.ss_family == AF_LOCAL) - if (setsockopt(fd, 0, LOCAL_CREDS, &one, sizeof one) < 0) + if (setsockopt(fd, 0, LOCAL_CREDS, &one, (socklen_t)sizeof one) + == -1) goto cleanup_svc_vc_create; xprt->xp_ltaddr.maxlen = xprt->xp_ltaddr.len = sslocal.ss_len; @@ -516,7 +517,7 @@ read_vc(caddr_t xprtp, caddr_t buf, int cfp = (struct cf_conn *)xprt->xp_p1; if (cfp->nonblock) { - len = read(sock, buf, (size_t)len); + len = (int)read(sock, buf, (size_t)len); if (len < 0) { if (errno == EAGAIN) len = 0; @@ -545,7 +546,7 @@ read_vc(caddr_t xprtp, caddr_t buf, int } } while ((pollfd.revents & POLLIN) == 0); - if ((len = read(sock, buf, (size_t)len)) > 0) { + if ((len = (int)read(sock, buf, (size_t)len)) > 0) { gettimeofday(&cfp->last_recv_time, NULL); return len; } @@ -578,7 +579,7 @@ write_vc(caddr_t xprtp, caddr_t buf, int gettimeofday(&tv0, NULL); for (cnt = len; cnt > 0; cnt -= i, buf += i) { - if ((i = write(xprt->xp_fd, buf, (size_t)cnt)) < 0) { + if ((i = (int)write(xprt->xp_fd, buf, (size_t)cnt)) < 0) { if (errno != EAGAIN || !cd->nonblock) { cd->strm_stat = XPRT_DIED; return -1; Index: rpc/xdr.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/xdr.c,v retrieving revision 1.28 diff -u -p -u -r1.28 xdr.c --- rpc/xdr.c 14 May 2006 02:15:31 -0000 1.28 +++ rpc/xdr.c 11 Mar 2012 15:11:39 -0000 @@ -108,9 +108,7 @@ static const char xdr_zero[BYTES_PER_XDR * Not a filter, but a convenient utility nonetheless */ void -xdr_free(proc, objp) - xdrproc_t proc; - char *objp; +xdr_free(xdrproc_t proc, char *objp) { XDR x; @@ -122,10 +120,7 @@ xdr_free(proc, objp) * XDR nothing */ bool_t -xdr_void(/* xdrs, addr */) - /* XDR *xdrs; */ - /* caddr_t addr; */ -{ +xdr_void(void) { return (TRUE); } @@ -135,9 +130,7 @@ xdr_void(/* xdrs, addr */) * XDR integers */ bool_t -xdr_int(xdrs, ip) - XDR *xdrs; - int *ip; +xdr_int(XDR *xdrs, int *ip) { long l; @@ -168,9 +161,7 @@ xdr_int(xdrs, ip) * XDR unsigned integers */ bool_t -xdr_u_int(xdrs, up) - XDR *xdrs; - u_int *up; +xdr_u_int(XDR *xdrs, u_int *up) { u_long l; @@ -203,9 +194,7 @@ xdr_u_int(xdrs, up) * same as xdr_u_long - open coded to save a proc call! */ bool_t -xdr_long(xdrs, lp) - XDR *xdrs; - long *lp; +xdr_long(XDR *xdrs, long *lp) { _DIAGASSERT(xdrs != NULL); @@ -228,9 +217,7 @@ xdr_long(xdrs, lp) * same as xdr_long - open coded to save a proc call! */ bool_t -xdr_u_long(xdrs, ulp) - XDR *xdrs; - u_long *ulp; +xdr_u_long(XDR *xdrs, u_long *ulp) { _DIAGASSERT(xdrs != NULL); @@ -254,9 +241,7 @@ xdr_u_long(xdrs, ulp) * same as xdr_u_int32_t - open coded to save a proc call! */ bool_t -xdr_int32_t(xdrs, int32_p) - XDR *xdrs; - int32_t *int32_p; +xdr_int32_t(XDR *xdrs, int32_t *int32_p) { long l; @@ -288,9 +273,7 @@ xdr_int32_t(xdrs, int32_p) * same as xdr_int32_t - open coded to save a proc call! */ bool_t -xdr_u_int32_t(xdrs, u_int32_p) - XDR *xdrs; - u_int32_t *u_int32_p; +xdr_u_int32_t(XDR *xdrs, u_int32_t *u_int32_p) { u_long l; @@ -322,9 +305,7 @@ xdr_u_int32_t(xdrs, u_int32_p) * XDR short integers */ bool_t -xdr_short(xdrs, sp) - XDR *xdrs; - short *sp; +xdr_short(XDR *xdrs, short *sp) { long l; @@ -355,9 +336,7 @@ xdr_short(xdrs, sp) * XDR unsigned short integers */ bool_t -xdr_u_short(xdrs, usp) - XDR *xdrs; - u_short *usp; +xdr_u_short(XDR *xdrs, u_short *usp) { u_long l; @@ -389,9 +368,7 @@ xdr_u_short(xdrs, usp) * XDR 16-bit integers */ bool_t -xdr_int16_t(xdrs, int16_p) - XDR *xdrs; - int16_t *int16_p; +xdr_int16_t(XDR *xdrs, int16_t *int16_p) { long l; @@ -422,9 +399,7 @@ xdr_int16_t(xdrs, int16_p) * XDR unsigned 16-bit integers */ bool_t -xdr_u_int16_t(xdrs, u_int16_p) - XDR *xdrs; - u_int16_t *u_int16_p; +xdr_u_int16_t(XDR *xdrs, u_int16_t *u_int16_p) { u_long l; @@ -456,9 +431,7 @@ xdr_u_int16_t(xdrs, u_int16_p) * XDR a char */ bool_t -xdr_char(xdrs, cp) - XDR *xdrs; - char *cp; +xdr_char(XDR *xdrs, char *cp) { int i; @@ -477,9 +450,7 @@ xdr_char(xdrs, cp) * XDR an unsigned char */ bool_t -xdr_u_char(xdrs, cp) - XDR *xdrs; - u_char *cp; +xdr_u_char(XDR *xdrs, u_char *cp) { u_int u; @@ -498,9 +469,7 @@ xdr_u_char(xdrs, cp) * XDR booleans */ bool_t -xdr_bool(xdrs, bp) - XDR *xdrs; - bool_t *bp; +xdr_bool(XDR *xdrs, bool_t *bp) { long lb; @@ -531,9 +500,7 @@ xdr_bool(xdrs, bp) * XDR enumerations */ bool_t -xdr_enum(xdrs, ep) - XDR *xdrs; - enum_t *ep; +xdr_enum(XDR *xdrs, enum_t *ep) { long l; @@ -566,10 +533,7 @@ xdr_enum(xdrs, ep) * cp points to the opaque object and cnt gives the byte length. */ bool_t -xdr_opaque(xdrs, cp, cnt) - XDR *xdrs; - caddr_t cp; - u_int cnt; +xdr_opaque(XDR *xdrs, caddr_t cp, u_int cnt) { u_int rndup; static int crud[BYTES_PER_XDR_UNIT]; @@ -620,11 +584,7 @@ xdr_opaque(xdrs, cp, cnt) * If *cpp is NULL maxsize bytes are allocated */ bool_t -xdr_bytes(xdrs, cpp, sizep, maxsize) - XDR *xdrs; - char **cpp; - u_int *sizep; - u_int maxsize; +xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) { char *sp; /* sp is the actual string pointer */ u_int nodesize; @@ -682,9 +642,7 @@ xdr_bytes(xdrs, cpp, sizep, maxsize) * Implemented here due to commonality of the object. */ bool_t -xdr_netobj(xdrs, np) - XDR *xdrs; - struct netobj *np; +xdr_netobj(XDR *xdrs, struct netobj *np) { _DIAGASSERT(xdrs != NULL); @@ -705,12 +663,13 @@ xdr_netobj(xdrs, np) * If there is no specific or default routine an error is returned. */ bool_t -xdr_union(xdrs, dscmp, unp, choices, dfault) - XDR *xdrs; - enum_t *dscmp; /* enum to decide which arm to work on */ - char *unp; /* the union itself */ - const struct xdr_discrim *choices; /* [value, xdr proc] for each arm */ - xdrproc_t dfault; /* default xdr routine */ +xdr_union( + XDR *xdrs, + enum_t *dscmp, /* enum to decide which arm to work on */ + char *unp, /* the union itself */ + const struct xdr_discrim *choices, /* [value, xdr proc] for each arm */ + xdrproc_t dfault /* default xdr routine */ +) { enum_t dscm; @@ -760,14 +719,12 @@ xdr_union(xdrs, dscmp, unp, choices, dfa * of the string as specified by a protocol. */ bool_t -xdr_string(xdrs, cpp, maxsize) - XDR *xdrs; - char **cpp; - u_int maxsize; +xdr_string(XDR *xdrs, char **cpp, u_int maxsize) { char *sp; /* sp is the actual string pointer */ u_int size = 0; /* XXX: GCC */ u_int nodesize; + size_t len; _DIAGASSERT(xdrs != NULL); _DIAGASSERT(cpp != NULL); @@ -784,7 +741,9 @@ xdr_string(xdrs, cpp, maxsize) } /* FALLTHROUGH */ case XDR_ENCODE: - size = strlen(sp); + len = strlen(sp); + _DIAGASSERT(__type_fit(u_int, len)); + size = (u_int)len; break; case XDR_DECODE: break; @@ -832,9 +791,7 @@ xdr_string(xdrs, cpp, maxsize) * routines like clnt_call */ bool_t -xdr_wrapstring(xdrs, cpp) - XDR *xdrs; - char **cpp; +xdr_wrapstring(XDR *xdrs, char **cpp) { _DIAGASSERT(xdrs != NULL); @@ -855,9 +812,7 @@ xdr_wrapstring(xdrs, cpp) * XDR 64-bit integers */ bool_t -xdr_int64_t(xdrs, llp) - XDR *xdrs; - int64_t *llp; +xdr_int64_t(XDR *xdrs, int64_t *llp) { u_long ul[2]; @@ -866,8 +821,10 @@ xdr_int64_t(xdrs, llp) switch (xdrs->x_op) { case XDR_ENCODE: - ul[0] = (u_long)((u_int64_t)*llp >> 32) & 0xffffffff; - ul[1] = (u_long)((u_int64_t)*llp) & 0xffffffff; + ul[0] = (u_long)((uint64_t)*llp >> 32) & + (uint64_t)0xffffffffULL; + ul[1] = (u_long)((uint64_t)*llp) & + (uint64_t)0xffffffffULL; if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE) return (FALSE); return (XDR_PUTLONG(xdrs, (long *)&ul[1])); @@ -891,9 +848,7 @@ xdr_int64_t(xdrs, llp) * XDR unsigned 64-bit integers */ bool_t -xdr_u_int64_t(xdrs, ullp) - XDR *xdrs; - u_int64_t *ullp; +xdr_u_int64_t(XDR *xdrs, u_int64_t *ullp) { u_long ul[2]; @@ -902,8 +857,8 @@ xdr_u_int64_t(xdrs, ullp) switch (xdrs->x_op) { case XDR_ENCODE: - ul[0] = (u_long)(*ullp >> 32) & 0xffffffff; - ul[1] = (u_long)(*ullp) & 0xffffffff; + ul[0] = (u_long)(*ullp >> 32) & 0xffffffffUL; + ul[1] = (u_long)(*ullp) & 0xffffffffUL; if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE) return (FALSE); return (XDR_PUTLONG(xdrs, (long *)&ul[1])); Index: rpc/xdr_rec.c =================================================================== RCS file: /cvsroot/src/lib/libc/rpc/xdr_rec.c,v retrieving revision 1.31 diff -u -p -u -r1.31 xdr_rec.c --- rpc/xdr_rec.c 23 Nov 2010 14:02:01 -0000 1.31 +++ rpc/xdr_rec.c 11 Mar 2012 15:11:39 -0000 @@ -62,6 +62,7 @@ __RCSID("$NetBSD: xdr_rec.c,v 1.31 2010/ #include <netinet/in.h> +#include <assert.h> #include <err.h> #include <stddef.h> #include <stdio.h> @@ -259,7 +260,7 @@ xdrrec_getlong(xdrs, lp) rstrm->in_finger += sizeof(int32_t); } else { if (! xdrrec_getbytes(xdrs, (char *)(void *)&mylong, - sizeof(int32_t))) + (u_int)sizeof(int32_t))) return (FALSE); *lp = (long)ntohl((u_int32_t)mylong); } @@ -334,7 +335,8 @@ xdrrec_putbytes(xdrs, addr, len) memmove(rstrm->out_finger, addr, current); rstrm->out_finger += current; addr += current; - len -= current; + _DIAGASSERT(__type_fit(u_int, current)); + len -= (u_int)current; if (rstrm->out_finger == rstrm->out_boundry) { rstrm->frag_sent = TRUE; if (! flush_out(rstrm, FALSE)) @@ -568,7 +570,8 @@ __xdrrec_getrec(xdrs, statp, expectdata) return FALSE; } rstrm->in_hdrp += n; - rstrm->in_hdrlen += n; + _DIAGASSERT(__type_fit(int, n)); + rstrm->in_hdrlen += (int)n; if (rstrm->in_hdrlen < (int)sizeof(rstrm->in_header)) { *statp = XPRT_MOREREQS; return FALSE; @@ -607,7 +610,8 @@ __xdrrec_getrec(xdrs, statp, expectdata) return FALSE; } - rstrm->in_received += n; + _DIAGASSERT(__type_fit(int, n)); + rstrm->in_received += (int)n; if (rstrm->in_received == rstrm->in_reclen) { rstrm->in_haveheader = FALSE; @@ -704,8 +708,10 @@ get_input_bytes(rstrm, addr, len) } while (len > 0) { - current = ((uintptr_t)rstrm->in_boundry - + uintptr_t d = ((uintptr_t)rstrm->in_boundry - (uintptr_t)rstrm->in_finger); + _DIAGASSERT(__type_fit(u_int, d)); + current = (u_int)d; if (current == 0) { if (! fill_input_buf(rstrm)) return (FALSE); @@ -728,7 +734,8 @@ set_input_fragment(rstrm) if (rstrm->nonblock) return FALSE; - if (! get_input_bytes(rstrm, (char *)(void *)&header, sizeof(header))) + if (! get_input_bytes(rstrm, (char *)(void *)&header, + (u_int)sizeof(header))) return (FALSE); header = ntohl(header); rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE; @@ -754,7 +761,7 @@ skip_input_bytes(rstrm, cnt) u_int32_t current; while (cnt > 0) { - current = (size_t)((long)rstrm->in_boundry - + current = (uint32_t)((long)rstrm->in_boundry - (long)rstrm->in_finger); if (current == 0) { if (! fill_input_buf(rstrm)) Index: stdio/fflush.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fflush.c,v retrieving revision 1.15 diff -u -p -u -r1.15 fflush.c --- stdio/fflush.c 7 Aug 2003 16:43:22 -0000 1.15 +++ stdio/fflush.c 11 Mar 2012 15:11:39 -0000 @@ -41,6 +41,7 @@ __RCSID("$NetBSD: fflush.c,v 1.15 2003/0 #endif #endif /* LIBC_SCCS and not lint */ +#include <stddef.h> #include <assert.h> #include <errno.h> #include <stdio.h> @@ -92,7 +93,9 @@ __sflush(fp) if ((p = fp->_bf._base) == NULL) return (0); - n = fp->_p - p; /* write this much */ + ptrdiff_t tp = fp->_p - p; + _DIAGASSERT(__type_fit(int, tp)); + n = (int)tp; /* write this much */ /* * Set these immediately to avoid problems with longjmp and to allow Index: stdio/fgetwc.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fgetwc.c,v retrieving revision 1.11 diff -u -p -u -r1.11 fgetwc.c --- stdio/fgetwc.c 25 Oct 2009 20:44:13 -0000 1.11 +++ stdio/fgetwc.c 11 Mar 2012 15:11:39 -0000 @@ -80,7 +80,8 @@ restart: nr = 1; } fp->_p += nr; - fp->_r -= nr; + _DIAGASSERT(__type_fit(int, fp->_r - nr)); + fp->_r -= (int)nr; return wc; } Index: stdio/fputs.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fputs.c,v retrieving revision 1.14 diff -u -p -u -r1.14 fputs.c --- stdio/fputs.c 22 Jun 2005 19:45:22 -0000 1.14 +++ stdio/fputs.c 11 Mar 2012 15:11:39 -0000 @@ -53,9 +53,7 @@ __RCSID("$NetBSD: fputs.c,v 1.14 2005/06 * Write the given string to the given file. */ int -fputs(s, fp) - const char *s; - FILE *fp; +fputs(const char *s, FILE *fp) { struct __suio uio; struct __siov iov; @@ -68,7 +66,7 @@ fputs(s, fp) s = "(null)"; iov.iov_base = __UNCONST(s); - iov.iov_len = uio.uio_resid = strlen(s); + uio.uio_resid = iov.iov_len = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; FLOCKFILE(fp); Index: stdio/fread.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fread.c,v retrieving revision 1.20 diff -u -p -u -r1.20 fread.c --- stdio/fread.c 25 Oct 2009 20:44:13 -0000 1.20 +++ stdio/fread.c 11 Mar 2012 15:11:39 -0000 @@ -88,7 +88,9 @@ fread(buf, size, count, fp) } } (void)memcpy(p, fp->_p, resid); - fp->_r -= resid; + + _DIAGASSERT(__type_fit(int, fp->_r - resid)); + fp->_r -= (int)resid; fp->_p += resid; FUNLOCKFILE(fp); return (count); Index: stdio/fseeko.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fseeko.c,v retrieving revision 1.9 diff -u -p -u -r1.9 fseeko.c --- stdio/fseeko.c 22 Jan 2012 18:36:17 -0000 1.9 +++ stdio/fseeko.c 11 Mar 2012 15:11:39 -0000 @@ -207,7 +207,8 @@ fseeko(FILE *fp, off_t offset, int whenc int o = (int)(target - curoff); fp->_p = fp->_bf._base + o; - fp->_r = n - o; + _DIAGASSERT(__type_fit(int, n - o)); + fp->_r = (int)(n - o); if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; @@ -236,7 +237,8 @@ fseeko(FILE *fp, off_t offset, int whenc if (__srefill(fp) || (size_t)fp->_r < n) goto dumb; fp->_p += n; - fp->_r -= n; + _DIAGASSERT(__type_fit(int, fp->_r - n)); + fp->_r -= (int)n; } FUNLOCKFILE(fp); return (0); Index: stdio/fvwrite.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fvwrite.c,v retrieving revision 1.22 diff -u -p -u -r1.22 fvwrite.c --- stdio/fvwrite.c 24 Mar 2011 02:29:33 -0000 1.22 +++ stdio/fvwrite.c 11 Mar 2012 15:11:40 -0000 @@ -42,6 +42,7 @@ __RCSID("$NetBSD: fvwrite.c,v 1.22 2011/ #endif /* LIBC_SCCS and not lint */ #include <assert.h> +#include <stddef.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -61,12 +62,12 @@ __sfvwrite(fp, uio) FILE *fp; struct __suio *uio; { - int len; + size_t len; char *p; struct __siov *iov; int w, s; char *nl; - int nlknown, nldist; + size_t nlknown, nldist; _DIAGASSERT(fp != NULL); _DIAGASSERT(uio != NULL); @@ -125,8 +126,8 @@ __sfvwrite(fp, uio) do { GETIOV(;); if ((fp->_flags & (__SALC | __SSTR)) == - (__SALC | __SSTR) && fp->_w < len) { - int blen = fp->_p - fp->_bf._base; + (__SALC | __SSTR) && (size_t)fp->_w < len) { + ptrdiff_t blen = fp->_p - fp->_bf._base; unsigned char *_base; int _size; @@ -134,7 +135,7 @@ __sfvwrite(fp, uio) _size = fp->_bf._size; do { _size = (_size << 1) + 1; - } while (_size < blen + len); + } while ((size_t)_size < blen + len); _base = realloc(fp->_bf._base, (size_t)(_size + 1)); if (_base == NULL) @@ -146,27 +147,27 @@ __sfvwrite(fp, uio) } w = fp->_w; if (fp->_flags & __SSTR) { - if (len < w) - w = len; + if (len < (size_t)w) + w = (int)len; COPY(w); /* copy MIN(fp->_w,len), */ fp->_w -= w; fp->_p += w; - w = len; /* but pretend copied all */ - } else if (fp->_p > fp->_bf._base && len > w) { + w = (int)len; /* but pretend copied all */ + } else if (fp->_p > fp->_bf._base && len > (size_t)w) { /* fill and flush */ COPY(w); /* fp->_w -= w; */ /* unneeded */ fp->_p += w; if (fflush(fp)) goto err; - } else if (len >= (w = fp->_bf._size)) { + } else if (len >= (size_t)(w = fp->_bf._size)) { /* write directly */ w = (*fp->_write)(fp->_cookie, p, w); if (w <= 0) goto err; } else { /* fill and done */ - w = len; + w = (int)len; COPY(w); fp->_w -= w; fp->_p += w; @@ -187,11 +188,11 @@ __sfvwrite(fp, uio) do { GETIOV(nlknown = 0); if (!nlknown) { - nl = memchr(p, '\n', (size_t)len); - nldist = nl ? nl + 1 - p : len + 1; + nl = memchr(p, '\n', len); + nldist = nl ? (size_t)(nl + 1 - p) : len + 1; nlknown = 1; } - s = MIN(len, nldist); + s = (int)MIN(len, nldist); w = fp->_w + fp->_bf._size; if (fp->_p > fp->_bf._base && s > w) { COPY(w); Index: stdio/fvwrite.h =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fvwrite.h,v retrieving revision 1.7 diff -u -p -u -r1.7 fvwrite.h --- stdio/fvwrite.h 7 Aug 2003 16:43:26 -0000 1.7 +++ stdio/fvwrite.h 11 Mar 2012 15:11:40 -0000 @@ -43,8 +43,8 @@ struct __siov { }; struct __suio { struct __siov *uio_iov; - int uio_iovcnt; - int uio_resid; + size_t uio_iovcnt; + size_t uio_resid; }; extern int __sfvwrite(FILE *, struct __suio *); Index: stdio/makebuf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/makebuf.c,v retrieving revision 1.15 diff -u -p -u -r1.15 makebuf.c --- stdio/makebuf.c 13 Mar 2008 15:40:00 -0000 1.15 +++ stdio/makebuf.c 11 Mar 2012 15:11:40 -0000 @@ -85,7 +85,8 @@ __smakebuf(fp) __cleanup = _cleanup; flags |= __SMBF; fp->_bf._base = fp->_p = p; - fp->_bf._size = size; + _DIAGASSERT(__type_fit(int, size)); + fp->_bf._size = (int)size; if (couldbetty && isatty(__sfileno(fp))) flags |= __SLBF; fp->_flags |= flags; Index: stdio/setvbuf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/setvbuf.c,v retrieving revision 1.17 diff -u -p -u -r1.17 setvbuf.c --- stdio/setvbuf.c 7 Aug 2003 16:43:31 -0000 1.17 +++ stdio/setvbuf.c 11 Mar 2012 15:11:40 -0000 @@ -152,7 +152,8 @@ nbf: flags |= __SLBF; fp->_flags = flags; fp->_bf._base = fp->_p = (unsigned char *)buf; - fp->_bf._size = size; + _DIAGASSERT(__type_fit(int, size)); + fp->_bf._size = (int)size; /* fp->_lbfsize is still 0 */ if (flags & __SWR) { /* @@ -162,8 +163,10 @@ nbf: if (flags & __SLBF) { fp->_w = 0; fp->_lbfsize = -fp->_bf._size; - } else - fp->_w = size; + } else { + _DIAGASSERT(__type_fit(int, size)); + fp->_w = (int)size; + } } else { /* begin/continue reading, or stay in intermediate state */ fp->_w = 0; Index: stdio/snprintf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/snprintf.c,v retrieving revision 1.22 diff -u -p -u -r1.22 snprintf.c --- stdio/snprintf.c 26 Oct 2007 19:48:14 -0000 1.22 +++ stdio/snprintf.c 11 Mar 2012 15:11:40 -0000 @@ -85,7 +85,8 @@ snprintf(char *str, size_t n, char const f._bf._size = f._w = 0; } else { f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n - 1; + _DIAGASSERT(__type_fit(int, n - 1)); + f._bf._size = f._w = (int)(n - 1); } ret = __vfprintf_unlocked(&f, fmt, ap); *f._p = 0; Index: stdio/sscanf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/sscanf.c,v retrieving revision 1.17 diff -u -p -u -r1.17 sscanf.c --- stdio/sscanf.c 11 Jan 2010 20:39:29 -0000 1.17 +++ stdio/sscanf.c 11 Mar 2012 15:11:40 -0000 @@ -69,6 +69,7 @@ sscanf(const char *str, char const *fmt, int ret; va_list ap; FILE f; + size_t len; struct __sfileext fext; _DIAGASSERT(str != NULL); @@ -77,7 +78,9 @@ sscanf(const char *str, char const *fmt, _FILEEXT_SETUP(&f, &fext); f._flags = __SRD; f._bf._base = f._p = __UNCONST(str); - f._bf._size = f._r = strlen(str); + len = strlen(str); + _DIAGASSERT(__type_fit(int, len)); + f._bf._size = f._r = (int)len; f._read = eofread; _UB(&f)._base = NULL; va_start(ap, fmt); Index: stdio/stdio.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/stdio.c,v retrieving revision 1.17 diff -u -p -u -r1.17 stdio.c --- stdio/stdio.c 22 Jan 2012 18:36:17 -0000 1.17 +++ stdio/stdio.c 11 Mar 2012 15:11:40 -0000 @@ -63,7 +63,7 @@ __sread(cookie, buf, n) int n; { FILE *fp = cookie; - int ret; + ssize_t ret; _DIAGASSERT(fp != NULL); _DIAGASSERT(buf != NULL); @@ -74,7 +74,8 @@ __sread(cookie, buf, n) fp->_offset += ret; else fp->_flags &= ~__SOFF; /* paranoia */ - return (ret); + + return (int)ret; } int @@ -91,7 +92,7 @@ __swrite(cookie, buf, n) if (fp->_flags & __SAPP) (void) lseek(__sfileno(fp), (off_t)0, SEEK_END); fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */ - return write(__sfileno(fp), buf, (size_t)n); + return (int)write(__sfileno(fp), buf, (size_t)n); } off_t Index: stdio/vfscanf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/vfscanf.c,v retrieving revision 1.41 diff -u -p -u -r1.41 vfscanf.c --- stdio/vfscanf.c 16 Dec 2010 17:42:27 -0000 1.41 +++ stdio/vfscanf.c 11 Mar 2012 15:11:40 -0000 @@ -109,7 +109,7 @@ __weak_alias(vfscanf,__svfscanf) static const u_char *__sccl(char *, const u_char *); #ifndef NO_FLOATING_POINT -static int parsefloat(FILE *, char *, char *); +static size_t parsefloat(FILE *, char *, char *); #endif int __scanfdebug = 0; @@ -161,7 +161,7 @@ __svfscanf_unlocked(FILE *fp, const char char *p0; /* saves original value of p when necessary */ int nassigned; /* number of fields assigned */ int nconversions; /* number of conversions */ - int nread; /* number of characters consumed from fp */ + size_t nread; /* number of characters consumed from fp */ int base; /* base argument to conversion function */ char ccltab[256]; /* character class table for %[...] */ char buf[BUF]; /* buffer for numeric and mb conversions */ @@ -325,9 +325,9 @@ literal: if (flags & SUPPRESS) /* ??? */ continue; if (flags & SHORTSHORT) - *va_arg(ap, char *) = nread; + *va_arg(ap, char *) = (char)nread; else if (flags & SHORT) - *va_arg(ap, short *) = nread; + *va_arg(ap, short *) = (short)nread; else if (flags & LONG) *va_arg(ap, long *) = nread; else if (flags & LONGLONG) @@ -339,7 +339,7 @@ literal: else if (flags & PTRDIFFT) *va_arg(ap, ptrdiff_t *) = nread; else - *va_arg(ap, int *) = nread; + *va_arg(ap, int *) = (int)nread; continue; default: @@ -439,7 +439,9 @@ literal: } } else { sum += width; - fp->_r -= width; + _DIAGASSERT(__type_fit(int, + fp->_r - width)); + fp->_r -= (int)width; fp->_p += width; break; } @@ -945,7 +947,7 @@ doswitch: } #ifndef NO_FLOATING_POINT -static int +static size_t parsefloat(FILE *fp, char *buf, char *end) { char *commit, *p; Index: stdio/vfwprintf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/vfwprintf.c,v retrieving revision 1.26 diff -u -p -u -r1.26 vfwprintf.c --- stdio/vfwprintf.c 17 Feb 2012 23:58:36 -0000 1.26 +++ stdio/vfwprintf.c 11 Mar 2012 15:11:41 -0000 @@ -724,7 +724,9 @@ WDECL(__vf,printf_unlocked)(FILE *fp, co } \ } while (/*CONSTCOND*/0) #define PRINTANDPAD(p, ep, len, with) do { \ - n2 = (ep) - (p); \ + ptrdiff_t td = (ep) - (p); \ + _DIAGASSERT(__type_fit(int, td)); \ + n2 = (int)td; \ if (n2 > (len)) \ n2 = (len); \ if (n2 > 0) \ @@ -837,7 +839,8 @@ WDECL(__vf,printf_unlocked)(FILE *fp, co for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) continue; - if ((n = fmt - cp) != 0) { + _DIAGASSERT(__type_fit(int, fmt - cp)); + if ((n = (int)(fmt - cp)) != 0) { if ((unsigned)ret + n > INT_MAX) { ret = END_OF_FILE; goto error; @@ -1055,11 +1058,15 @@ reswitch: switch (ch) { if (dtoaresult == NULL) goto oomem; - if (prec < 0) - prec = dtoaend - dtoaresult; + if (prec < 0) { + _DIAGASSERT(__type_fit(int, + dtoaend - dtoaresult)); + prec = (int)(dtoaend - dtoaresult); + } if (expt == INT_MAX) ox[1] = '\0'; - ndig = dtoaend - dtoaresult; + _DIAGASSERT(__type_fit(int, dtoaend - dtoaresult)); + ndig = (int)(dtoaend - dtoaresult); if (convbuf != NULL) free(convbuf); #ifndef NARROW @@ -1107,7 +1114,8 @@ fp_begin: } if (dtoaresult == NULL) goto oomem; - ndig = dtoaend - dtoaresult; + _DIAGASSERT(__type_fit(int, dtoaend - dtoaresult)); + ndig = (int)(dtoaend - dtoaresult); if (convbuf != NULL) free(convbuf); #ifndef NARROW @@ -1328,13 +1336,18 @@ fp_common: CHAR_T *p = MEMCHR(result, 0, (size_t)prec); if (p != NULL) { - size = p - result; + _DIAGASSERT(__type_fit(int, + p - result)); + size = (int)(p - result); if (size > prec) size = prec; } else size = prec; - } else - size = STRLEN(result); + } else { + size_t rlen = STRLEN(result); + _DIAGASSERT(__type_fit(int, rlen)); + size = (int)rlen; + } sign = '\0'; break; case 'U': @@ -1399,7 +1412,8 @@ number: if ((dprec = prec) >= 0) flags & GROUPING, thousands_sep, grouping); } - size = buf + BUF - result; + _DIAGASSERT(__type_fit(int, buf + BUF - result)); + size = (int)(buf + BUF - result); if (size > BUF) /* should never happen */ abort(); break; @@ -1929,7 +1943,7 @@ static int __grow_type_table (size_t nextarg, enum typeid **typetable, size_t *tablesize) { enum typeid *const oldtable = *typetable; - const int oldsize = *tablesize; + const size_t oldsize = *tablesize; enum typeid *newtable; size_t newsize = oldsize * 2; @@ -2038,6 +2052,7 @@ exponent(CHAR_T *p0, int expo, int fmtch *p++ = '0'; *p++ = to_char(expo); } - return (p - p0); + _DIAGASSERT(__type_fit(int, p - p0)); + return (int)(p - p0); } #endif /* !NO_FLOATING_POINT */ Index: stdio/vfwscanf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/vfwscanf.c,v retrieving revision 1.6 diff -u -p -u -r1.6 vfwscanf.c --- stdio/vfwscanf.c 21 Feb 2009 17:20:01 -0000 1.6 +++ stdio/vfwscanf.c 11 Mar 2012 15:11:41 -0000 @@ -49,6 +49,7 @@ __RCSID("$NetBSD: vfwscanf.c,v 1.6 2009/ #include "namespace.h" #include <ctype.h> #include <inttypes.h> +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h> @@ -147,7 +148,7 @@ __vfwscanf_unlocked(FILE * __restrict fp wchar_t *p0; /* saves original value of p when necessary */ int nassigned; /* number of fields assigned */ int nconversions; /* number of conversions */ - int nread; /* number of characters consumed from fp */ + size_t nread; /* number of characters consumed from fp */ int base; /* base argument to conversion function */ wchar_t buf[BUF]; /* buffer for numeric conversions */ const wchar_t *ccls; /* character class start */ @@ -327,9 +328,9 @@ literal: if (flags & SUPPRESS) /* ??? */ continue; if (flags & SHORTSHORT) - *va_arg(ap, char *) = nread; + *va_arg(ap, char *) = (char)nread; else if (flags & SHORT) - *va_arg(ap, short *) = nread; + *va_arg(ap, short *) = (short)nread; else if (flags & LONG) *va_arg(ap, long *) = nread; else if (flags & LONGLONG) @@ -341,7 +342,7 @@ literal: else if (flags & PTRDIFFT) *va_arg(ap, ptrdiff_t *) = nread; else - *va_arg(ap, int *) = nread; + *va_arg(ap, int *) = (int)nread; continue; default: @@ -450,7 +451,8 @@ literal: *p++ = (wchar_t)wi; if (wi != WEOF) ungetwc(wi, fp); - n = p - p0; + _DIAGASSERT(__type_fit(int, p - p0)); + n = (int)(p - p0); if (n == 0) goto match_failure; *p = 0; @@ -699,7 +701,8 @@ literal: *va_arg(ap, int *) = (int)res; nassigned++; } - nread += p - buf; + _DIAGASSERT(__type_fit(int, p - buf)); + nread += (int)(p - buf); nconversions++; break; @@ -891,6 +894,7 @@ parsedone: while (commit < --p) ungetwc(*p, fp); *++commit = '\0'; - return (commit - buf); + _DIAGASSERT(__type_fit(int, commit - buf)); + return (int)(commit - buf); } #endif Index: stdio/vsnprintf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/vsnprintf.c,v retrieving revision 1.23 diff -u -p -u -r1.23 vsnprintf.c --- stdio/vsnprintf.c 17 Jul 2011 20:54:34 -0000 1.23 +++ stdio/vsnprintf.c 11 Mar 2012 15:11:41 -0000 @@ -82,7 +82,8 @@ vsnprintf(char *str, size_t n, const cha f._bf._size = f._w = 0; } else { f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n - 1; + _DIAGASSERT(__type_fit(int, n - 1)); + f._bf._size = f._w = (int)(n - 1); } ret = __vfprintf_unlocked(&f, fmt, ap); *f._p = 0; Index: stdio/vsnprintf_ss.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/vsnprintf_ss.c,v retrieving revision 1.10 diff -u -p -u -r1.10 vsnprintf_ss.c --- stdio/vsnprintf_ss.c 17 Jul 2011 20:54:34 -0000 1.10 +++ stdio/vsnprintf_ss.c 11 Mar 2012 15:11:41 -0000 @@ -136,6 +136,7 @@ vsnprintf_ss(char *sbuf, size_t slen, co const char *xdigs; /* digits for [xX] conversion */ char bf[128]; /* space for %c, %[diouxX] */ char *tailp; /* tail pointer for snprintf */ + size_t len; static const char xdigs_lower[16] = "0123456789abcdef"; static const char xdigs_upper[16] = "0123456789ABCDEF"; @@ -330,13 +331,17 @@ reswitch: switch (ch) { char *p = memchr(cp, 0, (size_t)prec); if (p != NULL) { - size = p - cp; + _DIAGASSERT(__type_fit(int, p - cp)); + size = (int)(p - cp); if (size > prec) size = prec; } else size = prec; - } else - size = strlen(cp); + } else { + len = strlen(cp); + _DIAGASSERT(__type_fit(int, len)); + size = (int)len; + } sign = '\0'; break; case 'U': @@ -409,11 +414,14 @@ number: if ((dprec = prec) >= 0) default: /*XXXUNCONST*/ cp = __UNCONST("bug bad base"); - size = strlen(cp); + len = strlen(cp); + _DIAGASSERT(__type_fit(int, len)); + size = (int)len; goto skipsize; } } - size = bf + sizeof(bf) - cp; + _DIAGASSERT(__type_fit(int, bf + sizeof(bf) - cp)); + size = (int)(bf + sizeof(bf) - cp); skipsize: break; default: /* "%?" prints ?, unless ? is NUL */ Index: stdio/vsscanf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/vsscanf.c,v retrieving revision 1.16 diff -u -p -u -r1.16 vsscanf.c --- stdio/vsscanf.c 17 Jul 2011 20:54:34 -0000 1.16 +++ stdio/vsscanf.c 11 Mar 2012 15:11:41 -0000 @@ -65,6 +65,7 @@ vsscanf(const char *str, const char *fmt { FILE f; struct __sfileext fext; + size_t len; _DIAGASSERT(str != NULL); _DIAGASSERT(fmt != NULL); @@ -72,7 +73,9 @@ vsscanf(const char *str, const char *fmt _FILEEXT_SETUP(&f, &fext); f._flags = __SRD; f._bf._base = f._p = __UNCONST(str); - f._bf._size = f._r = strlen(str); + len = strlen(str); + _DIAGASSERT(__type_fit(int, len)); + f._bf._size = f._r = (int)len; f._read = eofread; _UB(&f)._base = NULL; return (__svfscanf_unlocked(&f, fmt, ap)); Index: stdio/vswscanf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/vswscanf.c,v retrieving revision 1.6 diff -u -p -u -r1.6 vswscanf.c --- stdio/vswscanf.c 11 Jan 2010 20:39:29 -0000 1.6 +++ stdio/vswscanf.c 11 Mar 2012 15:11:41 -0000 @@ -46,6 +46,7 @@ __RCSID("$NetBSD: vswscanf.c,v 1.6 2010/ #endif #endif /* LIBC_SCCS and not lint */ +#include <assert.h> #include <limits.h> #include <stdarg.h> #include <stdio.h> @@ -94,7 +95,8 @@ vswscanf(const wchar_t * __restrict str, f._file = -1; f._flags = __SRD; f._bf._base = f._p = (unsigned char *)mbstr; - f._bf._size = f._r = mlen; + _DIAGASSERT(__type_fit(int, mlen)); + f._bf._size = f._r = (int)mlen; f._read = eofread; _UB(&f)._base = NULL; r = __vfwscanf_unlocked(&f, fmt, ap); Index: stdio/wbuf.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/wbuf.c,v retrieving revision 1.13 diff -u -p -u -r1.13 wbuf.c --- stdio/wbuf.c 7 Aug 2003 16:43:35 -0000 1.13 +++ stdio/wbuf.c 11 Mar 2012 15:11:41 -0000 @@ -86,7 +86,8 @@ __swbuf(c, fp) * guarantees that putc() will always call wbuf() by setting _w * to 0, so we need not do anything else. */ - n = fp->_p - fp->_bf._base; + _DIAGASSERT(__type_fit(int, fp->_p - fp->_bf._base)); + n = (int)(fp->_p - fp->_bf._base); if (n >= fp->_bf._size) { if (fflush(fp)) return (EOF); Index: stdlib/l64a.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdlib/l64a.c,v retrieving revision 1.13 diff -u -p -u -r1.13 l64a.c --- stdlib/l64a.c 26 Jul 2003 19:24:54 -0000 1.13 +++ stdlib/l64a.c 11 Mar 2012 15:11:41 -0000 @@ -22,20 +22,16 @@ __weak_alias(l64a_r,_l64a_r) #endif char * -l64a (value) - long value; +l64a(long value) { static char buf[8]; - (void)l64a_r(value, buf, sizeof (buf)); + (void)l64a_r(value, buf, (int)sizeof (buf)); return buf; } int -l64a_r (value, buffer, buflen) - long value; - char *buffer; - int buflen; +l64a_r(long value, char *buffer, int buflen) { char *s = buffer; int digit; Index: stdlib/merge.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdlib/merge.c,v retrieving revision 1.13 diff -u -p -u -r1.13 merge.c --- stdlib/merge.c 18 May 2011 19:36:36 -0000 1.13 +++ stdlib/merge.c 11 Mar 2012 15:11:41 -0000 @@ -108,11 +108,8 @@ static void insertionsort(u_char *, size * Arguments are as for qsort. */ int -mergesort(base, nmemb, size, cmp) - void *base; - size_t nmemb; - size_t size; - int (*cmp)(const void *, const void *); +mergesort(void *base, size_t nmemb, size_t size, + int (*cmp)(const void *, const void *)) { size_t i; int sense; @@ -281,13 +278,12 @@ COPY: b = t; /* XXX: shouldn't this function be static? - lukem 990810 */ void -setup(list1, list2, n, size, cmp) - size_t n, size; - int (*cmp)(const void *, const void *); - u_char *list1, *list2; +setup(u_char *list1, u_char *list2, size_t n, size_t size, + int (*cmp)(const void *, const void *)) { - int i, length, size2, tmp, sense; + int length, tmp, sense; u_char *f1, *f2, *s, *l2, *last, *p2; + size_t size2, i; _DIAGASSERT(cmp != NULL); _DIAGASSERT(list1 != NULL); @@ -304,7 +300,7 @@ setup(list1, list2, n, size, cmp) * for simplicity. */ i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, (size_t)i, size, cmp); + insertionsort(list1 + (n - i) * size, i, size, cmp); last = list1 + size * (n - i); *EVAL(list2 + (last - list1)) = list2 + n * size; @@ -332,12 +328,12 @@ setup(list1, list2, n, size, cmp) if ((cmp(f2-size, f2) > 0) != sense) { p2 = *EVAL(p2) = f2 - list1 + list2; if (sense > 0) - reverse(f1, f2-size); + reverse(f1, f2 - size); f1 = f2; } } if (sense > 0) - reverse (f1, f2-size); + reverse(f1, f2 - size); f1 = f2; if (f2 < last || cmp(f2 - size, f2) > 0) p2 = *EVAL(p2) = f2 - list1 + list2; @@ -359,13 +355,11 @@ setup(list1, list2, n, size, cmp) * last 4 elements. */ static void -insertionsort(a, n, size, cmp) - u_char *a; - size_t n, size; - int (*cmp)(const void *, const void *); +insertionsort(u_char *a, size_t n, size_t size, + int (*cmp)(const void *, const void *)) { u_char *ai, *s, *t, *u, tmp; - int i; + size_t i; _DIAGASSERT(a != NULL); _DIAGASSERT(cmp != NULL); Index: stdlib/strfmon.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdlib/strfmon.c,v retrieving revision 1.8 diff -u -p -u -r1.8 strfmon.c --- stdlib/strfmon.c 14 Aug 2011 09:07:15 -0000 1.8 +++ stdlib/strfmon.c 11 Mar 2012 15:11:41 -0000 @@ -42,6 +42,7 @@ __RCSID("$NetBSD: strfmon.c,v 1.8 2011/0 #endif #include <sys/types.h> +#include <assert.h> #include <ctype.h> #include <errno.h> #include <limits.h> @@ -376,7 +377,8 @@ strfmon(char * __restrict s, size_t maxs while (dst - tmpptr < width) PRINT(' '); } else { - pad_size = dst-tmpptr; + _DIAGASSERT(__type_fit(int, dst - tmpptr)); + pad_size = dst - tmpptr; memmove(tmpptr + width-pad_size, tmpptr, (size_t) pad_size); memset(tmpptr, ' ', (size_t) width-pad_size); @@ -452,7 +454,7 @@ __calc_left_pad(int flags, char *cur_sym char cs_precedes, sep_by_space, sign_posn; const char *signstr; - int left_chars = 0; + size_t left_chars = 0; __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr); @@ -471,7 +473,8 @@ __calc_left_pad(int flags, char *cur_sym if (cs_precedes != 0) left_chars += strlen(signstr); } - return (left_chars); + _DIAGASSERT(__type_fit(int, left_chars)); + return (int)left_chars; } static int Index: sys/sched.c =================================================================== RCS file: /cvsroot/src/lib/libc/sys/sched.c,v retrieving revision 1.2 diff -u -p -u -r1.2 sched.c --- sys/sched.c 31 Oct 2008 00:29:19 -0000 1.2 +++ sys/sched.c 11 Mar 2012 15:11:41 -0000 @@ -104,7 +104,7 @@ sched_get_priority_max(int policy) errno = EINVAL; return -1; } - return sysconf(_SC_SCHED_PRI_MAX); + return (int)sysconf(_SC_SCHED_PRI_MAX); } int @@ -115,7 +115,7 @@ sched_get_priority_min(int policy) errno = EINVAL; return -1; } - return sysconf(_SC_SCHED_PRI_MIN); + return (int)sysconf(_SC_SCHED_PRI_MIN); } int Index: time/localtime.c =================================================================== RCS file: /cvsroot/src/lib/libc/time/localtime.c,v retrieving revision 1.65 diff -u -p -u -r1.65 localtime.c --- time/localtime.c 7 Jan 2012 15:19:35 -0000 1.65 +++ time/localtime.c 11 Mar 2012 15:11:42 -0000 @@ -370,7 +370,7 @@ tzload(timezone_t sp, const char *name, int i; int fid; int stored; - int nread; + ssize_t nread; typedef union { struct tzhead tzhead; char buf[2 * sizeof(struct tzhead) + @@ -457,8 +457,8 @@ tzload(timezone_t sp, const char *name, ttisgmtcnt) /* ttisgmts */ goto oops; for (i = 0; i < sp->timecnt; ++i) { - sp->ats[i] = (stored == 4) ? - detzcode(p) : detzcode64(p); + sp->ats[i] = (time_t)((stored == 4) ? + detzcode(p) : detzcode64(p)); p += stored; } for (i = 0; i < sp->timecnt; ++i) { @@ -487,8 +487,8 @@ tzload(timezone_t sp, const char *name, struct lsinfo * lsisp; lsisp = &sp->lsis[i]; - lsisp->ls_trans = (stored == 4) ? - detzcode(p) : detzcode64(p); + lsisp->ls_trans = (time_t)((stored == 4) ? + detzcode(p) : detzcode64(p)); p += stored; lsisp->ls_corr = detzcode(p); p += 4; @@ -873,7 +873,7 @@ transtime(const time_t janfirst, const i ** add SECSPERDAY times the day number-1 to the time of ** January 1, midnight, to get the day. */ - value = janfirst + (rulep->r_day - 1) * SECSPERDAY; + value = (time_t)(janfirst + (rulep->r_day - 1) * SECSPERDAY); if (leapyear && rulep->r_day >= 60) value += SECSPERDAY; break; @@ -884,7 +884,7 @@ transtime(const time_t janfirst, const i ** Just add SECSPERDAY times the day number to the time of ** January 1, midnight, to get the day. */ - value = janfirst + rulep->r_day * SECSPERDAY; + value = (time_t)(janfirst + rulep->r_day * SECSPERDAY); break; case MONTH_NTH_DAY_OF_WEEK: @@ -893,7 +893,7 @@ transtime(const time_t janfirst, const i */ value = janfirst; for (i = 0; i < rulep->r_mon - 1; ++i) - value += mon_lengths[leapyear][i] * SECSPERDAY; + value += (time_t)(mon_lengths[leapyear][i] * SECSPERDAY); /* ** Use Zeller's Congruence to get day-of-week of first day of @@ -926,7 +926,7 @@ transtime(const time_t janfirst, const i /* ** "d" is the day-of-month (zero-origin) of the day we want. */ - value += d * SECSPERDAY; + value += (time_t)(d * SECSPERDAY); break; } @@ -936,7 +936,7 @@ transtime(const time_t janfirst, const i ** time on that day, add the transition time and the current offset ** from UTC. */ - return value + rulep->r_time + offset; + return (time_t)(value + rulep->r_time + offset); } /* @@ -1032,7 +1032,7 @@ tzparse(timezone_t sp, const char *name, memset(sp->ttis, 0, sizeof(sp->ttis)); sp->ttis[0].tt_gmtoff = -dstoffset; sp->ttis[0].tt_isdst = 1; - sp->ttis[0].tt_abbrind = stdlen + 1; + sp->ttis[0].tt_abbrind = (int)(stdlen + 1); sp->ttis[1].tt_gmtoff = -stdoffset; sp->ttis[1].tt_isdst = 0; sp->ttis[1].tt_abbrind = 0; @@ -1062,8 +1062,8 @@ tzparse(timezone_t sp, const char *name, } sp->timecnt += 2; newfirst = janfirst; - newfirst += year_lengths[isleap(year)] * - SECSPERDAY; + newfirst += (time_t) + (year_lengths[isleap(year)] * SECSPERDAY); if (newfirst <= janfirst) break; janfirst = newfirst; @@ -1129,11 +1129,11 @@ tzparse(timezone_t sp, const char *name, ** offset. */ if (isdst && !sp->ttis[j].tt_ttisstd) { - sp->ats[i] += dstoffset - - theirdstoffset; + sp->ats[i] += (time_t) + (dstoffset - theirdstoffset); } else { - sp->ats[i] += stdoffset - - theirstdoffset; + sp->ats[i] += (time_t) + (stdoffset - theirstdoffset); } } theiroffset = -sp->ttis[j].tt_gmtoff; @@ -1150,7 +1150,7 @@ tzparse(timezone_t sp, const char *name, sp->ttis[0].tt_abbrind = 0; sp->ttis[1].tt_gmtoff = -dstoffset; sp->ttis[1].tt_isdst = TRUE; - sp->ttis[1].tt_abbrind = stdlen + 1; + sp->ttis[1].tt_abbrind = (int)(stdlen + 1); sp->typecnt = 2; } } else { @@ -1162,9 +1162,9 @@ tzparse(timezone_t sp, const char *name, sp->ttis[0].tt_isdst = 0; sp->ttis[0].tt_abbrind = 0; } - sp->charcnt = stdlen + 1; + sp->charcnt = (int)(stdlen + 1); if (dstlen != 0) - sp->charcnt += dstlen + 1; + sp->charcnt += (int)(dstlen + 1); if ((size_t) sp->charcnt > sizeof sp->chars) return -1; cp = sp->chars; @@ -1332,7 +1332,8 @@ localsub(const timezone_t sp, const time seconds = sp->ats[0] - t; else seconds = t - sp->ats[sp->timecnt - 1]; --seconds; - tcycles = seconds / YEARSPERREPEAT / AVGSECSPERYEAR; + tcycles = (time_t) + (seconds / YEARSPERREPEAT / AVGSECSPERYEAR); ++tcycles; icycles = tcycles; if (tcycles - icycles >= 1 || icycles - tcycles >= 1) @@ -1573,7 +1574,7 @@ timesub(const timezone_t sp, const time_ } } y = EPOCH_YEAR; - tdays = *timep / SECSPERDAY; + tdays = (time_t)(*timep / SECSPERDAY); rem = (long) (*timep - tdays * SECSPERDAY); while (tdays < 0 || tdays >= year_lengths[isleap(y)]) { int newy; @@ -1600,7 +1601,7 @@ timesub(const timezone_t sp, const time_ long seconds; seconds = tdays * SECSPERDAY + 0.5; - tdays = seconds / SECSPERDAY; + tdays = (time_t)(seconds / SECSPERDAY); rem += (long) (seconds - tdays * SECSPERDAY); } /* @@ -1848,7 +1849,7 @@ again: } if (long_increment_overflow(&y, -TM_YEAR_BASE)) goto overflow; - yourtm.tm_year = y; + yourtm.tm_year = (int)y; if (yourtm.tm_year != y) goto overflow; if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN) @@ -1962,8 +1963,8 @@ again: for (j = sp->typecnt - 1; j >= 0; --j) { if (sp->ttis[j].tt_isdst == yourtm.tm_isdst) continue; - newt = t + sp->ttis[j].tt_gmtoff - - sp->ttis[i].tt_gmtoff; + newt = (time_t)(t + sp->ttis[j].tt_gmtoff - + sp->ttis[i].tt_gmtoff); if ((*funcp)(sp, &newt, offset, &mytm) == NULL) continue; if (tmcomp(&mytm, &yourtm) != 0) @@ -2201,7 +2202,7 @@ leapcorr(const timezone_t sp, time_t *ti time_t time2posix_z(const timezone_t sp, time_t t) { - return t - leapcorr(sp, &t); + return (time_t)(t - leapcorr(sp, &t)); } time_t @@ -2210,7 +2211,7 @@ time2posix(time_t t) time_t result; rwlock_wrlock(&lcl_lock); tzset_unlocked(); - result = t - leapcorr(lclptr, &t); + result = (time_t)(t - leapcorr(lclptr, &t)); rwlock_unlock(&lcl_lock); return (result); } @@ -2227,12 +2228,12 @@ posix2time_z(const timezone_t sp, time_t ** hit, the corresponding time doesn't exist, ** so we return an adjacent second. */ - x = t + leapcorr(sp, &t); - y = x - leapcorr(sp, &x); + x = (time_t)(t + leapcorr(sp, &t)); + y = (time_t)(x - leapcorr(sp, &x)); if (y < t) { do { x++; - y = x - leapcorr(sp, &x); + y = (time_t)(x - leapcorr(sp, &x)); } while (y < t); if (t != y) { return x - 1; @@ -2240,7 +2241,7 @@ posix2time_z(const timezone_t sp, time_t } else if (y > t) { do { --x; - y = x - leapcorr(sp, &x); + y = (time_t)(x - leapcorr(sp, &x)); } while (y > t); if (t != y) { return x + 1; Index: time/strptime.c =================================================================== RCS file: /cvsroot/src/lib/libc/time/strptime.c,v retrieving revision 1.35 diff -u -p -u -r1.35 strptime.c --- time/strptime.c 14 Dec 2009 20:45:02 -0000 1.35 +++ time/strptime.c 11 Mar 2012 15:11:42 -0000 @@ -554,7 +554,7 @@ find_string(const u_char *bp, int *tgt, const char * const *n2, int c) { int i; - unsigned int len; + size_t len; /* check full name - then abbreviated ones */ for (; n1 != NULL; n1 = n2, n2 = NULL) { Index: yp/xdryp.c =================================================================== RCS file: /cvsroot/src/lib/libc/yp/xdryp.c,v retrieving revision 1.30 diff -u -p -u -r1.30 xdryp.c --- yp/xdryp.c 11 May 2006 17:11:57 -0000 1.30 +++ yp/xdryp.c 11 Mar 2012 15:11:42 -0000 @@ -124,9 +124,7 @@ __warn_references(xdr_domainname, "warning: this program uses xdr_domainname(), which is deprecated and buggy.") bool_t -xdr_domainname(xdrs, objp) - XDR *xdrs; - char *objp; +xdr_domainname(XDR *xdrs, char *objp) { _DIAGASSERT(xdrs != NULL); @@ -139,9 +137,7 @@ __warn_references(xdr_peername, "warning: this program uses xdr_peername(), which is deprecated and buggy.") bool_t -xdr_peername(xdrs, objp) - XDR *xdrs; - char *objp; +xdr_peername(XDR *xdrs, char *objp) { _DIAGASSERT(xdrs != NULL); @@ -154,9 +150,7 @@ __warn_references(xdr_mapname, "warning: this program uses xdr_mapname(), which is deprecated and buggy.") bool_t -xdr_mapname(xdrs, objp) - XDR *xdrs; - char *objp; +xdr_mapname(XDR *xdrs, char *objp) { _DIAGASSERT(xdrs != NULL); @@ -166,9 +160,7 @@ xdr_mapname(xdrs, objp) } bool_t -xdr_ypdomain_wrap_string(xdrs, objp) - XDR *xdrs; - char **objp; +xdr_ypdomain_wrap_string(XDR *xdrs, char **objp) { _DIAGASSERT(xdrs != NULL); @@ -178,9 +170,7 @@ xdr_ypdomain_wrap_string(xdrs, objp) } bool_t -xdr_ypmap_wrap_string(xdrs, objp) - XDR *xdrs; - char **objp; +xdr_ypmap_wrap_string(XDR *xdrs, char **objp) { _DIAGASSERT(xdrs != NULL); @@ -190,9 +180,7 @@ xdr_ypmap_wrap_string(xdrs, objp) } bool_t -xdr_ypowner_wrap_string(xdrs, objp) - XDR *xdrs; - char **objp; +xdr_ypowner_wrap_string(XDR *xdrs, char **objp) { _DIAGASSERT(xdrs != NULL); @@ -202,9 +190,7 @@ xdr_ypowner_wrap_string(xdrs, objp) } bool_t -xdr_datum(xdrs, objp) - XDR *xdrs; - datum *objp; +xdr_datum(XDR *xdrs, datum *objp) { _DIAGASSERT(xdrs != NULL); @@ -215,9 +201,7 @@ xdr_datum(xdrs, objp) } bool_t -xdr_ypreq_key(xdrs, objp) - XDR *xdrs; - struct ypreq_key *objp; +xdr_ypreq_key(XDR *xdrs, struct ypreq_key *objp) { _DIAGASSERT(xdrs != NULL); @@ -236,9 +220,7 @@ xdr_ypreq_key(xdrs, objp) } bool_t -xdr_ypreq_nokey(xdrs, objp) - XDR *xdrs; - struct ypreq_nokey *objp; +xdr_ypreq_nokey(XDR *xdrs, struct ypreq_nokey *objp) { _DIAGASSERT(xdrs != NULL); @@ -254,22 +236,18 @@ xdr_ypreq_nokey(xdrs, objp) } bool_t -xdr_yp_inaddr(xdrs, objp) - XDR *xdrs; - struct in_addr *objp; +xdr_yp_inaddr(XDR *xdrs, struct in_addr *objp) { _DIAGASSERT(xdrs != NULL); _DIAGASSERT(objp != NULL); return xdr_opaque(xdrs, (caddr_t)(void *)&objp->s_addr, - sizeof objp->s_addr); + (u_int)sizeof objp->s_addr); } static bool_t -xdr_ypbind_binding(xdrs, objp) - XDR *xdrs; - struct ypbind_binding *objp; +xdr_ypbind_binding(XDR *xdrs, struct ypbind_binding *objp) { _DIAGASSERT(xdrs != NULL); @@ -279,16 +257,14 @@ xdr_ypbind_binding(xdrs, objp) return FALSE; if (!xdr_opaque(xdrs, (void *)&objp->ypbind_binding_port, - sizeof objp->ypbind_binding_port)) + (u_int)sizeof objp->ypbind_binding_port)) return FALSE; return TRUE; } static bool_t -xdr_ypbind_resptype(xdrs, objp) - XDR *xdrs; - enum ypbind_resptype *objp; +xdr_ypbind_resptype(XDR *xdrs, enum ypbind_resptype *objp) { _DIAGASSERT(xdrs != NULL); @@ -298,9 +274,7 @@ xdr_ypbind_resptype(xdrs, objp) } static bool_t -xdr_ypstat(xdrs, objp) - XDR *xdrs; - enum ypbind_resptype *objp; +xdr_ypstat(XDR *xdrs, enum ypbind_resptype *objp) { _DIAGASSERT(xdrs != NULL); @@ -310,9 +284,7 @@ xdr_ypstat(xdrs, objp) } bool_t -xdr_ypbind_resp(xdrs, objp) - XDR *xdrs; - struct ypbind_resp *objp; +xdr_ypbind_resp(XDR *xdrs, struct ypbind_resp *objp) { _DIAGASSERT(xdrs != NULL); @@ -337,9 +309,7 @@ xdr_ypbind_resp(xdrs, objp) } bool_t -xdr_ypresp_val(xdrs, objp) - XDR *xdrs; - struct ypresp_val *objp; +xdr_ypresp_val(XDR *xdrs, struct ypresp_val *objp) { _DIAGASSERT(xdrs != NULL); @@ -355,9 +325,7 @@ xdr_ypresp_val(xdrs, objp) } bool_t -xdr_ypbind_setdom(xdrs, objp) - XDR *xdrs; - struct ypbind_setdom *objp; +xdr_ypbind_setdom(XDR *xdrs, struct ypbind_setdom *objp) { char *cp; @@ -379,9 +347,7 @@ xdr_ypbind_setdom(xdrs, objp) } bool_t -xdr_ypresp_key_val(xdrs, objp) - XDR *xdrs; - struct ypresp_key_val *objp; +xdr_ypresp_key_val(XDR *xdrs, struct ypresp_key_val *objp) { _DIAGASSERT(xdrs != NULL); @@ -400,9 +366,7 @@ xdr_ypresp_key_val(xdrs, objp) } bool_t -xdr_ypall(xdrs, incallback) - XDR *xdrs; - struct ypall_callback *incallback; +xdr_ypall(XDR *xdrs, struct ypall_callback *incallback) { struct ypresp_key_val out; char key[YPMAXRECORD], val[YPMAXRECORD]; @@ -448,9 +412,7 @@ xdr_ypall(xdrs, incallback) } bool_t -xdr_ypresp_master(xdrs, objp) - XDR *xdrs; - struct ypresp_master *objp; +xdr_ypresp_master(XDR *xdrs, struct ypresp_master *objp) { _DIAGASSERT(xdrs != NULL); @@ -466,9 +428,7 @@ xdr_ypresp_master(xdrs, objp) } static bool_t -xdr_ypmaplist_str(xdrs, objp) - XDR *xdrs; - char *objp; +xdr_ypmaplist_str(XDR *xdrs, char *objp) { _DIAGASSERT(xdrs != NULL); @@ -478,9 +438,7 @@ xdr_ypmaplist_str(xdrs, objp) } bool_t -xdr_ypmaplist(xdrs, objp) - XDR *xdrs; - struct ypmaplist *objp; +xdr_ypmaplist(XDR *xdrs, struct ypmaplist *objp) { _DIAGASSERT(xdrs != NULL); @@ -490,16 +448,14 @@ xdr_ypmaplist(xdrs, objp) return FALSE; if (!xdr_pointer(xdrs, (char **)(void *)&objp->ypml_next, - sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist)) + (u_int)sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist)) return FALSE; return TRUE; } bool_t -xdr_ypresp_maplist(xdrs, objp) - XDR *xdrs; - struct ypresp_maplist *objp; +xdr_ypresp_maplist(XDR *xdrs, struct ypresp_maplist *objp) { _DIAGASSERT(xdrs != NULL); @@ -509,16 +465,14 @@ xdr_ypresp_maplist(xdrs, objp) return FALSE; if (!xdr_pointer(xdrs, (char **)(void *)&objp->list, - sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist)) + (u_int)sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist)) return FALSE; return TRUE; } bool_t -xdr_ypresp_order(xdrs, objp) - XDR *xdrs; - struct ypresp_order *objp; +xdr_ypresp_order(XDR *xdrs, struct ypresp_order *objp) { _DIAGASSERT(xdrs != NULL); @@ -534,9 +488,7 @@ xdr_ypresp_order(xdrs, objp) } bool_t -xdr_ypreq_xfr(xdrs, objp) - XDR *xdrs; - struct ypreq_xfr *objp; +xdr_ypreq_xfr(XDR *xdrs, struct ypreq_xfr *objp) { _DIAGASSERT(xdrs != NULL); @@ -558,9 +510,7 @@ xdr_ypreq_xfr(xdrs, objp) } bool_t -xdr_ypmap_parms(xdrs, objp) - XDR *xdrs; - struct ypmap_parms *objp; +xdr_ypmap_parms(XDR *xdrs, struct ypmap_parms *objp) { _DIAGASSERT(xdrs != NULL); @@ -582,9 +532,7 @@ xdr_ypmap_parms(xdrs, objp) } bool_t -xdr_yppushresp_xfr(xdrs, objp) - XDR *xdrs; - struct yppushresp_xfr *objp; +xdr_yppushresp_xfr(XDR *xdrs, struct yppushresp_xfr *objp) { _DIAGASSERT(xdrs != NULL);