Date: Mon, 22 Jan 2018 02:08:10 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328238 - in head/sys: cam/scsi dev/mps fs/cd9660 fs/nandfs fs/nfsclient kern netpfil/ipfw netsmb x86/x86 Message-ID: <201801220208.w0M28AGH066757@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Mon Jan 22 02:08:10 2018 New Revision: 328238 URL: https://svnweb.freebsd.org/changeset/base/328238 Log: Unsign some values related to allocation. When allocating memory through malloc(9), we always expect the amount of memory requested to be unsigned as a negative value would either stand for an error or an overflow. Unsign some values, found when considering the use of mallocarray(9), to avoid unnecessary casting. Also consider that indexes should be of at least the same size/type as the upper limit they pretend to index. MFC after: 3 weeks Modified: head/sys/cam/scsi/scsi_ch.c head/sys/dev/mps/mps.c head/sys/fs/cd9660/cd9660_vnops.c head/sys/fs/nandfs/nandfs_vfsops.c head/sys/fs/nfsclient/nfs_clvnops.c head/sys/kern/kern_exec.c head/sys/kern/link_elf_obj.c head/sys/kern/subr_hash.c head/sys/kern/uipc_usrreq.c head/sys/netpfil/ipfw/ip_fw_sockopt.c head/sys/netpfil/ipfw/ip_fw_table_algo.c head/sys/netsmb/smb_crypt.c head/sys/x86/x86/mca.c Modified: head/sys/cam/scsi/scsi_ch.c ============================================================================== --- head/sys/cam/scsi/scsi_ch.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/cam/scsi/scsi_ch.c Mon Jan 22 02:08:10 2018 (r328238) @@ -1198,13 +1198,14 @@ chgetelemstatus(struct cam_periph *periph, int scsi_ve struct read_element_status_descriptor *desc; caddr_t data = NULL; size_t size, desclen; - int avail, i, error = 0; + u_int avail, i; int curdata, dvcid, sense_flags; int try_no_dvcid = 0; struct changer_element_status *user_data = NULL; struct ch_softc *softc; union ccb *ccb; int chet = cesr->cesr_element_type; + int error = 0; int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0; softc = (struct ch_softc *)periph->softc; Modified: head/sys/dev/mps/mps.c ============================================================================== --- head/sys/dev/mps/mps.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/dev/mps/mps.c Mon Jan 22 02:08:10 2018 (r328238) @@ -1164,7 +1164,7 @@ static int mps_alloc_queues(struct mps_softc *sc) { struct mps_queue *q; - int nq, i; + u_int nq, i; nq = sc->msi_msgs; mps_dprint(sc, MPS_INIT|MPS_XINFO, "Allocating %d I/O queues\n", nq); Modified: head/sys/fs/cd9660/cd9660_vnops.c ============================================================================== --- head/sys/fs/cd9660/cd9660_vnops.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/fs/cd9660/cd9660_vnops.c Mon Jan 22 02:08:10 2018 (r328238) @@ -481,7 +481,7 @@ cd9660_readdir(ap) int error = 0; int reclen; u_short namelen; - int ncookies = 0; + u_int ncookies = 0; u_long *cookies = NULL; cd_ino_t ino; Modified: head/sys/fs/nandfs/nandfs_vfsops.c ============================================================================== --- head/sys/fs/nandfs/nandfs_vfsops.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/fs/nandfs/nandfs_vfsops.c Mon Jan 22 02:08:10 2018 (r328238) @@ -561,7 +561,7 @@ nandfs_read_structures(struct nandfs_device *fsdev) { struct nandfs_fsdata *fsdata, *fsdatat; struct nandfs_super_block *sblocks, *ssblock; - int nsbs, nfsds, i; + u_int nsbs, nfsds, i; int error = 0; int nrsbs; Modified: head/sys/fs/nfsclient/nfs_clvnops.c ============================================================================== --- head/sys/fs/nfsclient/nfs_clvnops.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/fs/nfsclient/nfs_clvnops.c Mon Jan 22 02:08:10 2018 (r328238) @@ -2666,7 +2666,7 @@ ncl_flush(struct vnode *vp, int waitfor, struct thread #define NFS_COMMITBVECSIZ 20 #endif struct buf *bvec_on_stack[NFS_COMMITBVECSIZ]; - int bvecsize = 0, bveccount; + u_int bvecsize = 0, bveccount; if (called_from_renewthread != 0) slptimeo = hz; Modified: head/sys/kern/kern_exec.c ============================================================================== --- head/sys/kern/kern_exec.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/kern/kern_exec.c Mon Jan 22 02:08:10 2018 (r328238) @@ -1693,7 +1693,7 @@ int exec_register(const struct execsw *execsw_arg) { const struct execsw **es, **xs, **newexecsw; - int count = 2; /* New slot and trailing NULL */ + u_int count = 2; /* New slot and trailing NULL */ if (execsw) for (es = execsw; *es; es++) Modified: head/sys/kern/link_elf_obj.c ============================================================================== --- head/sys/kern/link_elf_obj.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/kern/link_elf_obj.c Mon Jan 22 02:08:10 2018 (r328238) @@ -97,10 +97,10 @@ typedef struct elf_file { Elf_Shdr *e_shdr; Elf_progent *progtab; - int nprogtab; + u_int nprogtab; Elf_relaent *relatab; - int nrelatab; + u_int nrelatab; Elf_relent *reltab; int nreltab; @@ -985,7 +985,7 @@ static void link_elf_unload_file(linker_file_t file) { elf_file_t ef = (elf_file_t) file; - int i; + u_int i; /* Notify MD code that a module is being unloaded. */ elf_cpu_unload_file(file); Modified: head/sys/kern/subr_hash.c ============================================================================== --- head/sys/kern/subr_hash.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/kern/subr_hash.c Mon Jan 22 02:08:10 2018 (r328238) @@ -57,9 +57,8 @@ void * hashinit_flags(int elements, struct malloc_type *type, u_long *hashmask, int flags) { - long hashsize; + long hashsize, i; LIST_HEAD(generic, generic) *hashtbl; - int i; KASSERT(elements > 0, ("%s: bad elements", __func__)); /* Exactly one of HASH_WAITOK and HASH_NOWAIT must be set. */ @@ -114,9 +113,8 @@ static const int primes[] = { 1, 13, 31, 61, 127, 251, void * phashinit_flags(int elements, struct malloc_type *type, u_long *nentries, int flags) { - long hashsize; + long hashsize, i; LIST_HEAD(generic, generic) *hashtbl; - int i; KASSERT(elements > 0, ("%s: bad elements", __func__)); /* Exactly one of HASH_WAITOK and HASH_NOWAIT must be set. */ Modified: head/sys/kern/uipc_usrreq.c ============================================================================== --- head/sys/kern/uipc_usrreq.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/kern/uipc_usrreq.c Mon Jan 22 02:08:10 2018 (r328238) @@ -1554,13 +1554,13 @@ unp_disconnect(struct unpcb *unp, struct unpcb *unp2) static int unp_pcblist(SYSCTL_HANDLER_ARGS) { - int error, i, n; - int freeunp; struct unpcb *unp, **unp_list; unp_gen_t gencnt; struct xunpgen *xug; struct unp_head *head; struct xunpcb *xu; + u_int i; + int freeunp, error, n; switch ((intptr_t)arg1) { case SOCK_STREAM: Modified: head/sys/netpfil/ipfw/ip_fw_sockopt.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_sockopt.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/netpfil/ipfw/ip_fw_sockopt.c Mon Jan 22 02:08:10 2018 (r328238) @@ -355,7 +355,7 @@ get_map(struct ip_fw_chain *chain, int extra, int lock for (;;) { struct ip_fw **map; - int i, mflags; + u_int i, mflags; mflags = M_ZERO | ((locked != 0) ? M_NOWAIT : M_WAITOK); Modified: head/sys/netpfil/ipfw/ip_fw_table_algo.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_table_algo.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/netpfil/ipfw/ip_fw_table_algo.c Mon Jan 22 02:08:10 2018 (r328238) @@ -3266,10 +3266,10 @@ static int ta_init_fhash(struct ip_fw_chain *ch, void **ta_state, struct table_info *ti, char *data, uint8_t tflags) { - int i; struct fhash_cfg *cfg; struct fhashentry4 *fe4; struct fhashentry6 *fe6; + u_int i; cfg = malloc(sizeof(struct fhash_cfg), M_IPFW, M_WAITOK | M_ZERO); @@ -3672,7 +3672,7 @@ ta_prepare_mod_fhash(void *ta_buf, uint64_t *pflags) { struct mod_item *mi; struct fhashbhead *head; - int i; + u_int i; mi = (struct mod_item *)ta_buf; Modified: head/sys/netsmb/smb_crypt.c ============================================================================== --- head/sys/netsmb/smb_crypt.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/netsmb/smb_crypt.c Mon Jan 22 02:08:10 2018 (r328238) @@ -118,7 +118,7 @@ smb_ntencrypt(const u_char *apwd, u_char *C8, u_char * u_char S21[21]; u_int16_t *unipwd; MD4_CTX *ctxp; - int len; + u_int len; len = strlen(apwd); unipwd = malloc((len + 1) * sizeof(u_int16_t), M_SMBTEMP, M_WAITOK); @@ -148,7 +148,7 @@ smb_calcmackey(struct smb_vc *vcp) { const char *pwd; u_int16_t *unipwd; - int len; + u_int len; MD4_CTX md4; u_char S16[16], S21[21]; Modified: head/sys/x86/x86/mca.c ============================================================================== --- head/sys/x86/x86/mca.c Mon Jan 22 01:50:10 2018 (r328237) +++ head/sys/x86/x86/mca.c Mon Jan 22 02:08:10 2018 (r328238) @@ -841,7 +841,7 @@ cmci_setup(void) static void amd_thresholding_setup(void) { - int i; + u_int i; amd_et_state = malloc((mp_maxid + 1) * sizeof(struct amd_et_state *), M_MCA, M_WAITOK);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801220208.w0M28AGH066757>