From a94a2945be9bad33563a9de9bdcba1ef276ba555 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Wed, 24 Jan 2018 17:58:48 +0000 Subject: [PATCH] ext2fs|ufs: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: 2 weeks --- sys/fs/ext2fs/ext2_lookup.c | 2 +- sys/ufs/ffs/ffs_softdep.c | 3 ++- sys/ufs/ufs/ufs_dirhash.c | 3 ++- sys/ufs/ufs/ufs_vnops.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/fs/ext2fs/ext2_lookup.c b/sys/fs/ext2fs/ext2_lookup.c index 39245a59e0ab..3ae2d7ac42bd 100644 --- a/sys/fs/ext2fs/ext2_lookup.c +++ b/sys/fs/ext2fs/ext2_lookup.c @@ -145,9 +145,9 @@ ext2_readdir(struct vop_readdir_args *ap) off_t offset, startoffset; size_t readcnt, skipcnt; ssize_t startresid; - int ncookies; int DIRBLKSIZ = VTOI(ap->a_vp)->i_e2fs->e2fs_bsize; int error; + u_int ncookies; if (uio->uio_offset < 0) return (EINVAL); diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index d2b16859ce54..7d434a99f0be 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -2466,7 +2466,8 @@ softdep_mount(devvp, mp, fs, cred) struct ufsmount *ump; struct cg *cgp; struct buf *bp; - int i, error, cyl; + u_int cyl, i; + int error; sdp = malloc(sizeof(struct mount_softdeps), M_MOUNTDATA, M_WAITOK | M_ZERO); diff --git a/sys/ufs/ufs/ufs_dirhash.c b/sys/ufs/ufs/ufs_dirhash.c index 77bef146d6fd..2f1174d33657 100644 --- a/sys/ufs/ufs/ufs_dirhash.c +++ b/sys/ufs/ufs/ufs_dirhash.c @@ -349,7 +349,8 @@ ufsdirhash_build(struct inode *ip) struct direct *ep; struct vnode *vp; doff_t bmask, pos; - int dirblocks, i, j, memreqd, nblocks, narrays, nslots, slot; + u_int dirblocks, i, narrays, nblocks, nslots; + int j, memreqd, slot; /* Take care of a decreased sysctl value. */ while (ufs_dirhashmem > ufs_dirhashmaxmem) { diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index 73482efc257c..479091a9182d 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -2170,7 +2170,7 @@ ufs_readdir(ap) off_t offset, startoffset; size_t readcnt, skipcnt; ssize_t startresid; - int ncookies; + u_int ncookies; int error; if (uio->uio_offset < 0)