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
This commit is contained in:
Pedro F. Giffuni 2018-01-22 02:08:10 +00:00
parent b8d1747e75
commit d821d36419
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=328238
13 changed files with 20 additions and 21 deletions

View file

@ -1198,13 +1198,14 @@ chgetelemstatus(struct cam_periph *periph, int scsi_version, u_long cmd,
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;

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -2666,7 +2666,7 @@ ncl_flush(struct vnode *vp, int waitfor, struct thread *td,
#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;

View file

@ -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++)

View file

@ -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);

View file

@ -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, 509, 761, 1021, 1531,
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. */

View file

@ -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:

View file

@ -355,7 +355,7 @@ get_map(struct ip_fw_chain *chain, int extra, int locked)
for (;;) {
struct ip_fw **map;
int i, mflags;
u_int i, mflags;
mflags = M_ZERO | ((locked != 0) ? M_NOWAIT : M_WAITOK);

View file

@ -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;

View file

@ -118,7 +118,7 @@ smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN)
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];

View file

@ -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);