fsx: fix build with WARNS=6

* signed/unsigned comparisons
* use standard warn(3)
* Suppress warnings about local vars and funcs not declared static
* const-correctness
* declaration shadows a variable in the global scope

Reviewed by:	kevans
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D26516
This commit is contained in:
Alan Somers 2020-09-21 17:48:28 +00:00
parent 45f6508149
commit 34e0b83ccb
2 changed files with 24 additions and 44 deletions

View File

@ -4,4 +4,9 @@ PROG= fsx
MAN= MAN=
NO_WMISSING_VARIABLE_DECLARATIONS=
.include <bsd.prog.mk> .include <bsd.prog.mk>
# Don't require static declarations. It's line noise in a single-file program.
CWARNFLAGS+= -Wno-strict-prototypes -Wno-missing-prototypes

View File

@ -112,7 +112,7 @@ int closeprob = 0; /* -c flag */
int invlprob = 0; /* -i flag */ int invlprob = 0; /* -i flag */
int debug = 0; /* -d flag */ int debug = 0; /* -d flag */
unsigned long debugstart = 0; /* -D flag */ unsigned long debugstart = 0; /* -D flag */
unsigned long maxfilelen = 256 * 1024; /* -l flag */ off_t maxfilelen = 256 * 1024; /* -l flag */
int sizechecks = 1; /* -n flag disables them */ int sizechecks = 1; /* -n flag disables them */
int maxoplen = 64 * 1024; /* -o flag */ int maxoplen = 64 * 1024; /* -o flag */
int quiet = 0; /* -q flag */ int quiet = 0; /* -q flag */
@ -138,32 +138,7 @@ int invl = 0;
void void
vwarnc(code, fmt, ap) prt(const char *fmt, ...)
int code;
const char *fmt;
va_list ap;
{
fprintf(stderr, "fsx: ");
if (fmt != NULL) {
vfprintf(stderr, fmt, ap);
fprintf(stderr, ": ");
}
fprintf(stderr, "%s\n", strerror(code));
}
void
warn(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vwarnc(errno, fmt, ap);
va_end(ap);
}
void
prt(char *fmt, ...)
{ {
va_list args; va_list args;
@ -179,7 +154,7 @@ prt(char *fmt, ...)
} }
void void
prterr(char *prefix) prterr(const char *prefix)
{ {
prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno)); prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
} }
@ -317,12 +292,12 @@ logdump(void)
void void
save_buffer(char *buffer, off_t bufferlength, int fd) save_buffer(char *buffer, off_t bufferlength, int savefd)
{ {
off_t ret; off_t ret;
ssize_t byteswritten; ssize_t byteswritten;
if (fd <= 0 || bufferlength == 0) if (savefd <= 0 || bufferlength == 0)
return; return;
if (bufferlength > SSIZE_MAX) { if (bufferlength > SSIZE_MAX) {
@ -330,7 +305,7 @@ save_buffer(char *buffer, off_t bufferlength, int fd)
exit(67); exit(67);
} }
if (lite) { if (lite) {
off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END); off_t size_by_seek = lseek(savefd, (off_t)0, SEEK_END);
if (size_by_seek == (off_t)-1) if (size_by_seek == (off_t)-1)
prterr("save_buffer: lseek eof"); prterr("save_buffer: lseek eof");
else if (bufferlength > size_by_seek) { else if (bufferlength > size_by_seek) {
@ -340,11 +315,11 @@ save_buffer(char *buffer, off_t bufferlength, int fd)
} }
} }
ret = lseek(fd, (off_t)0, SEEK_SET); ret = lseek(savefd, (off_t)0, SEEK_SET);
if (ret == (off_t)-1) if (ret == (off_t)-1)
prterr("save_buffer: lseek 0"); prterr("save_buffer: lseek 0");
byteswritten = write(fd, buffer, (size_t)bufferlength); byteswritten = write(savefd, buffer, (size_t)bufferlength);
if (byteswritten != bufferlength) { if (byteswritten != bufferlength) {
if (byteswritten == -1) if (byteswritten == -1)
prterr("save_buffer write"); prterr("save_buffer write");
@ -458,10 +433,10 @@ check_trunc_hack(void)
void void
doread(unsigned offset, unsigned size) doread(off_t offset, off_t size)
{ {
off_t ret; off_t ret;
unsigned iret; ssize_t iret;
offset -= offset % readbdy; offset -= offset % readbdy;
if (size == 0) { if (size == 0) {
@ -509,7 +484,7 @@ doread(unsigned offset, unsigned size)
void void
check_eofpage(char *s, unsigned offset, char *p, int size) check_eofpage(const char *s, unsigned offset, char *p, int size)
{ {
uintptr_t last_page, should_be_zero; uintptr_t last_page, should_be_zero;
@ -592,7 +567,7 @@ domapread(unsigned offset, unsigned size)
void void
gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size) gendata(unsigned offset, unsigned size)
{ {
while (size--) { while (size--) {
good_buf[offset] = testcalls % 256; good_buf[offset] = testcalls % 256;
@ -607,7 +582,7 @@ void
dowrite(unsigned offset, unsigned size) dowrite(unsigned offset, unsigned size)
{ {
off_t ret; off_t ret;
unsigned iret; ssize_t iret;
offset -= offset % writebdy; offset -= offset % writebdy;
if (size == 0) { if (size == 0) {
@ -619,7 +594,7 @@ dowrite(unsigned offset, unsigned size)
log4(OP_WRITE, offset, size, file_size); log4(OP_WRITE, offset, size, file_size);
gendata(original_buf, good_buf, offset, size); gendata(offset, size);
if (file_size < offset + size) { if (file_size < offset + size) {
if (file_size < offset) if (file_size < offset)
memset(good_buf + file_size, '\0', offset - file_size); memset(good_buf + file_size, '\0', offset - file_size);
@ -677,7 +652,7 @@ domapwrite(unsigned offset, unsigned size)
log4(OP_MAPWRITE, offset, size, 0); log4(OP_MAPWRITE, offset, size, 0);
gendata(original_buf, good_buf, offset, size); gendata(offset, size);
if (file_size < offset + size) { if (file_size < offset + size) {
if (file_size < offset) if (file_size < offset)
memset(good_buf + file_size, '\0', offset - file_size); memset(good_buf + file_size, '\0', offset - file_size);
@ -842,8 +817,8 @@ doinvl(void)
void void
test(void) test(void)
{ {
unsigned long offset; off_t offset;
unsigned long size = maxoplen; off_t size = maxoplen;
unsigned long rv = random(); unsigned long rv = random();
unsigned long op = rv % (3 + !lite + mapped_writes); unsigned long op = rv % (3 + !lite + mapped_writes);
@ -858,9 +833,9 @@ test(void)
testcalls++; testcalls++;
if (closeprob) if (closeprob)
closeopen = (rv >> 3) < (1 << 28) / closeprob; closeopen = (rv >> 3) < (1ul << 28) / closeprob;
if (invlprob) if (invlprob)
invl = (rv >> 3) < (1 << 28) / invlprob; invl = (rv >> 3) < (1ul << 28) / invlprob;
if (debugstart > 0 && testcalls >= debugstart) if (debugstart > 0 && testcalls >= debugstart)
debug = 1; debug = 1;