From 8c579f0aedd859ef27a70af2fb2bfe665aba3487 Mon Sep 17 00:00:00 2001 From: zrj Date: Tue, 18 Oct 2016 11:35:17 +0300 Subject: [PATCH] restore(8): Use size_t were appropriate. Mostly WARNS=3 cleanup. Also add vlatile to prevent clobbering. --- sbin/restore/dirs.c | 8 ++++---- sbin/restore/extern.h | 6 +++--- sbin/restore/interactive.c | 11 ++++++----- sbin/restore/tape.c | 30 +++++++++++++++--------------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c index 607d7b1b2e..c7c25371b5 100644 --- a/sbin/restore/dirs.c +++ b/sbin/restore/dirs.c @@ -116,7 +116,7 @@ static void dcvt(struct odirect *, struct direct *); static void flushent(void); static struct inotab *inotablookup(ufs1_ino_t); static RST_DIR *opendirfile(const char *); -static void putdir(char *, long); +static void putdir(char *, size_t); static void putent(struct direct *); static void rst_seekdir(RST_DIR *, long, long); static long rst_telldir(RST_DIR *); @@ -261,7 +261,7 @@ treescan(char *pname, ufs1_ino_t ino, long (*todo)(char *, ufs1_ino_t, int)) */ while (dp != NULL) { locname[namelen] = '\0'; - if (namelen + dp->d_namlen >= sizeof(locname)) { + if ((size_t)(namelen + dp->d_namlen) >= sizeof(locname)) { fprintf(stderr, "%s%s: name exceeds %zu char\n", locname, dp->d_name, sizeof(locname) - 1); } else { @@ -326,13 +326,13 @@ searchdir(ufs1_ino_t inum, char *name) * Put the directory entries in the directory file */ static void -putdir(char *buf, long size) +putdir(char *buf, size_t size) { struct direct cvtbuf; struct odirect *odp; struct odirect *eodp; struct direct *dp; - long loc, i; + size_t loc, i; if (cvtflag) { eodp = (struct odirect *)&buf[size]; diff --git a/sbin/restore/extern.h b/sbin/restore/extern.h index a82e02a4d4..04c84c1897 100644 --- a/sbin/restore/extern.h +++ b/sbin/restore/extern.h @@ -34,7 +34,7 @@ struct entry *addentry(char *, ufs1_ino_t, int); long addfile(char *, ufs1_ino_t, int); int addwhiteout(char *); void badentry(struct entry *, char *); -void canon(char *, char *, int); +void canon(char *, char *, size_t); void checkrestore(void); void closemt(void); void createfiles(void); @@ -54,7 +54,7 @@ void freeentry(struct entry *); void freename(char *); int genliteraldir(char *, ufs1_ino_t); char *gentempname(struct entry *); -void getfile(void (*)(char *, long), void (*)(char *, long)); +void getfile(void (*)(char *, size_t), void (*)(char *, size_t)); void getvol(long); void initsymtable(char *); int inodetype(ufs1_ino_t); @@ -96,7 +96,7 @@ void swabst(u_char *, u_char *); void treescan(char *, ufs1_ino_t, long (*)(char *, ufs1_ino_t, int)); ufs1_ino_t upperbnd(ufs1_ino_t); long verifyfile(char *, ufs1_ino_t, int); -void xtrnull(char *, long); +void xtrnull(char *, size_t); /* From ../dump/dumprmt.c */ void rmtclose(void); diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c index b8e7d88136..0ffa72cf44 100644 --- a/sbin/restore/interactive.c +++ b/sbin/restore/interactive.c @@ -73,7 +73,7 @@ struct arglist { static char *copynext(char *, char *); static int fcmp(const void *, const void *); static void formatf(struct afile *, int); -static void getcmd(char *, char *, char *, int, struct arglist *); +static void getcmd(char *, char *, char *, size_t, struct arglist *); struct dirent *glob_readdir(RST_DIR *dirp); static int glob_stat(const char *, struct stat *); static void mkentry(char *, struct direct *, struct afile *); @@ -291,7 +291,7 @@ loop: * eliminate any embedded ".." components. */ static void -getcmd(char *curdir, char *cmd, char *name, int size, struct arglist *ap) +getcmd(char *curdir, char *cmd, char *name, size_t size, struct arglist *ap) { char *cp; static char input[BUFSIZ]; @@ -425,7 +425,7 @@ copynext(char *input, char *output) * remove any embedded "." and ".." components. */ void -canon(char *rawname, char *canonname, int len) +canon(char *rawname, char *canonname, size_t len) { char *cp, *np; @@ -497,7 +497,7 @@ printlist(char *name, char *basename) list = &single; mkentry(name, dp, list); len = strlen(basename) + 1; - if (strlen(name) - len > single.len) { + if (strlen(name) - len > (unsigned short)single.len) { freename(single.fname); single.fname = savename(&name[len]); single.len = strlen(single.fname); @@ -623,7 +623,8 @@ static void formatf(struct afile *list, int nentry) { struct afile *fp, *endlist; - int width, bigino, haveprefix, havepostfix; + unsigned int bigino; + int width, haveprefix, havepostfix; int i, j, w, precision = 0, columns, lines; width = 0; diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 18181d26c7..61d0a31f44 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -93,12 +93,12 @@ static u_long swabl(u_long); static u_char *swablong(u_char *, int); static u_char *swabshort(u_char *, int); static void terminateinput(void); -static void xtrfile(char *, long); -static void xtrlnkfile(char *, long); -static void xtrlnkskip(char *, long); -static void xtrmap(char *, long); -static void xtrmapskip(char *, long); -static void xtrskip(char *, long); +static void xtrfile(char *, size_t); +static void xtrlnkfile(char *, size_t); +static void xtrlnkskip(char *, size_t); +static void xtrmap(char *, size_t); +static void xtrmapskip(char *, size_t); +static void xtrskip(char *, size_t); static int readmapflag; @@ -673,10 +673,10 @@ skipfile(void) * to the skip function. */ void -getfile(void (*fill) (char *, long), void (*skip) (char *, long)) +getfile(void (*fill)(char *, size_t), void (*skip)(char *, size_t)) { int i; - int curblk = 0; + volatile int curblk = 0; /* avoid -Wclobbered */ quad_t size = spcl.c_dinode.di_size; static char clearedbuf[MAXBSIZE]; char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE]; @@ -732,7 +732,7 @@ loop: * Write out the next block of a file. */ static void -xtrfile(char *buf, long size) +xtrfile(char *buf, size_t size) { if (Nflag) @@ -749,7 +749,7 @@ xtrfile(char *buf, long size) */ /* ARGSUSED */ static void -xtrskip(char *buf, long size) +xtrskip(char *buf, size_t size) { if (lseek(ofile, size, SEEK_CUR) == -1) { @@ -764,7 +764,7 @@ xtrskip(char *buf, long size) * Collect the next block of a symbolic link. */ static void -xtrlnkfile(char *buf, long size) +xtrlnkfile(char *buf, size_t size) { pathlen += size; @@ -781,7 +781,7 @@ xtrlnkfile(char *buf, long size) */ /* ARGSUSED */ static void -xtrlnkskip(char *buf, long size) +xtrlnkskip(char *buf, size_t size) { fprintf(stderr, "unallocated block in symbolic link %s\n", @@ -793,7 +793,7 @@ xtrlnkskip(char *buf, long size) * Collect the next block of a bit map. */ static void -xtrmap(char *buf, long size) +xtrmap(char *buf, size_t size) { memmove(map, buf, size); @@ -805,7 +805,7 @@ xtrmap(char *buf, long size) */ /* ARGSUSED */ static void -xtrmapskip(char *buf, long size) +xtrmapskip(char *buf, size_t size) { panic("hole in map\n"); @@ -817,7 +817,7 @@ xtrmapskip(char *buf, long size) */ /* ARGSUSED */ void -xtrnull(char *buf, long size) +xtrnull(char *buf, size_t size) { return; -- 2.41.0