stand: Minor cleanup

Replace a cast '0' for a null pointers with NULL
Replace a 'goto loop' with a do-while loop in ufs and ext2fs.
Cast cp pointer to uintptr_t to test to see if it's aligned rather than long.

[ minor tweaks based on my & hps' review, reworded commit message ]
Reviewed by: imp, hps
Pull Request: https://github.com/freebsd/freebsd-src/pull/547
This commit is contained in:
Alfonso 2023-02-27 16:19:54 -07:00 committed by Warner Losh
parent 9630e237ab
commit 68160fbd1f
3 changed files with 27 additions and 24 deletions

View file

@ -796,10 +796,11 @@ ext2fs_close(struct open_file *f)
struct file *fp = (struct file *)f->f_fsdata;
int level;
f->f_fsdata = (void *)0;
if (fp == (struct file *)0)
if (fp == NULL)
return (0);
f->f_fsdata = NULL;
for (level = 0; level < EXT2_NIADDR; level++) {
if (fp->f_blk[level])
free(fp->f_blk[level]);
@ -891,16 +892,17 @@ ext2fs_readdir(struct open_file *f, struct dirent *d)
/*
* assume that a directory entry will not be split across blocks
*/
again:
if (fp->f_seekp >= fp->f_di.di_size)
return (ENOENT);
error = buf_read_file(f, &buf, &buf_size);
if (error)
return (error);
ed = (struct ext2dirent *)buf;
fp->f_seekp += ed->d_reclen;
if (ed->d_ino == (ino_t)0)
goto again;
do {
if (fp->f_seekp >= fp->f_di.di_size)
return (ENOENT);
error = buf_read_file(f, &buf, &buf_size);
if (error)
return (error);
ed = (struct ext2dirent *)buf;
fp->f_seekp += ed->d_reclen;
} while (ed->d_ino == (ino_t)0);
d->d_type = EXTFTODT(ed->d_type);
strncpy(d->d_name, ed->d_name, ed->d_namlen);
d->d_name[ed->d_namlen] = '\0';

View file

@ -61,7 +61,7 @@ in_cksum(void *p, int len)
sum += v + *cp++;
len--;
}
if (((long)cp & 1) == 0) {
if (((uintptr_t)cp & 1) == 0) {
while ((len -= 2) >= 0) {
sum += *(u_short *)cp;
cp += 2;

View file

@ -409,7 +409,7 @@ buf_read_file(struct open_file *f, char **buf_p, size_t *size_p)
block_size = sblksize(fs, DIP(fp, di_size), file_block);
if (file_block != fp->f_buf_blkno) {
if (fp->f_buf == (char *)0)
if (fp->f_buf == NULL)
fp->f_buf = malloc(fs->fs_bsize);
rc = block_map(f, file_block, &disk_block);
@ -888,16 +888,17 @@ ufs_readdir(struct open_file *f, struct dirent *d)
/*
* assume that a directory entry will not be split across blocks
*/
again:
if (fp->f_seekp >= DIP(fp, di_size))
return (ENOENT);
error = buf_read_file(f, &buf, &buf_size);
if (error)
return (error);
dp = (struct direct *)buf;
fp->f_seekp += dp->d_reclen;
if (dp->d_ino == (ino_t)0)
goto again;
do {
if (fp->f_seekp >= DIP(fp, di_size))
return (ENOENT);
error = buf_read_file(f, &buf, &buf_size);
if (error)
return (error);
dp = (struct direct *)buf;
fp->f_seekp += dp->d_reclen;
} while (dp->d_ino == (ino_t)0);
d->d_type = dp->d_type;
strcpy(d->d_name, dp->d_name);
return (0);