mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-13 14:40:22 +00:00
ext2fs: use mallocarray(9).
Focus on code where we are doing multiplications within malloc(9). These are not likely to overflow, however the change is still useful as some static checkers can benefit from the allocation attributes we use for mallocarray.
This commit is contained in:
parent
f2fcff28d0
commit
9703326e8f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=328056
@ -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);
|
||||
@ -160,7 +160,8 @@ ext2_readdir(struct vop_readdir_args *ap)
|
||||
ncookies = ip->i_size - uio->uio_offset;
|
||||
ncookies = ncookies / (offsetof(struct ext2fs_direct_2,
|
||||
e2d_namlen) + 4) + 1;
|
||||
cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
|
||||
cookies = mallocarray(ncookies, sizeof(*cookies), M_TEMP,
|
||||
M_WAITOK);
|
||||
*ap->a_ncookies = ncookies;
|
||||
*ap->a_cookies = cookies;
|
||||
} else {
|
||||
|
@ -400,9 +400,9 @@ compute_sb_data(struct vnode *devvp, struct ext2fs *es,
|
||||
fs->e2fs_bsize / sizeof(struct ext2_gd));
|
||||
}
|
||||
fs->e2fs_gdbcount = howmany(fs->e2fs_gcount, e2fs_descpb);
|
||||
fs->e2fs_gd = malloc(e2fs_gdbcount_alloc * fs->e2fs_bsize,
|
||||
fs->e2fs_gd = mallocarray(e2fs_gdbcount_alloc, fs->e2fs_bsize,
|
||||
M_EXT2MNT, M_WAITOK | M_ZERO);
|
||||
fs->e2fs_contigdirs = malloc(fs->e2fs_gcount *
|
||||
fs->e2fs_contigdirs = mallocarray(fs->e2fs_gcount,
|
||||
sizeof(*fs->e2fs_contigdirs), M_EXT2MNT, M_WAITOK | M_ZERO);
|
||||
|
||||
/*
|
||||
@ -683,7 +683,8 @@ ext2_mountfs(struct vnode *devvp, struct mount *mp)
|
||||
for (i = 0; i < ump->um_e2fs->e2fs_gcount; i++, sump++) {
|
||||
*lp++ = ump->um_e2fs->e2fs_contigsumsize;
|
||||
sump->cs_init = 0;
|
||||
sump->cs_sum = malloc((ump->um_e2fs->e2fs_contigsumsize + 1) *
|
||||
sump->cs_sum = mallocarray(
|
||||
ump->um_e2fs->e2fs_contigsumsize + 1,
|
||||
sizeof(int32_t), M_EXT2MNT, M_WAITOK | M_ZERO);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user