From 67febcc5e8d252f6f13784dfc2b540bacd4dda77 Mon Sep 17 00:00:00 2001 From: Stelian Pop Date: Fri, 11 Jun 2010 11:19:17 +0000 Subject: [PATCH] Fix some warn_unused_result compile warnings --- CHANGES | 4 +++- common/dumprmt.c | 8 +++++--- restore/dirs.c | 39 ++++++++++++++++++++++-------------- restore/symtab.c | 8 ++++---- restore/tape.c | 48 +++++++++++++++++++++++++++++---------------- restore/utilities.c | 5 +++-- restore/xattr.c | 12 +++++++----- rmt/cipher.c | 6 +++++- rmt/rmt.c | 26 +++++++++++++++--------- 9 files changed, 99 insertions(+), 57 deletions(-) diff --git a/CHANGES b/CHANGES index dcdf046..8ff2dfd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -$Id: CHANGES,v 1.315 2010/06/11 09:57:31 stelian Exp $ +$Id: CHANGES,v 1.316 2010/06/11 11:19:17 stelian Exp $ Changes between versions 0.4b42 and 0.4b43 (released ?????????????) =================================================================== @@ -57,6 +57,8 @@ Changes between versions 0.4b42 and 0.4b43 (released ?????????????) 12. Extract dumped UNIX sockets instead of ignoring them. (Sourceforge bug #3007216). +13. Compiler warning fixes (mainly warn_unused_result ones). + Changes between versions 0.4b41 and 0.4b42 (released June 18, 2009) =================================================================== diff --git a/common/dumprmt.c b/common/dumprmt.c index e05325c..ba824f2 100644 --- a/common/dumprmt.c +++ b/common/dumprmt.c @@ -37,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: dumprmt.c,v 1.29 2006/03/13 10:33:44 stelian Exp $"; + "$Id: dumprmt.c,v 1.30 2010/06/11 11:19:17 stelian Exp $"; #endif /* not lint */ #include @@ -342,8 +342,10 @@ rmtwrite(const char *buf, size_t count) char line[30]; (void)snprintf(line, sizeof (line), "W%ld\n", (long)count); - write(tormtape, line, strlen(line)); - write(tormtape, buf, count); + if (write(tormtape, line, strlen(line)) != strlen(line)) + return -1; + if (write(tormtape, buf, count) != count) + return -1; return (rmtreply("write")); } diff --git a/restore/dirs.c b/restore/dirs.c index 2717f94..b987b69 100644 --- a/restore/dirs.c +++ b/restore/dirs.c @@ -42,7 +42,7 @@ #ifndef lint static const char rcsid[] = - "$Id: dirs.c,v 1.35 2008/04/17 15:16:47 stelian Exp $"; + "$Id: dirs.c,v 1.36 2010/06/11 11:19:17 stelian Exp $"; #endif /* not lint */ #include @@ -495,7 +495,7 @@ putent(struct direct *dp) if (dirloc + dp->d_reclen > DIRBLKSIZ) { ((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev; - if ( fwrite(dirbuf, 1, DIRBLKSIZ, df) != DIRBLKSIZ ) + if ( fwrite(dirbuf, DIRBLKSIZ, 1, df) != 1 ) err(1,"cannot write to file %s", dirfile); dirloc = 0; } @@ -683,13 +683,17 @@ setdirmodes(int flags) clearerr(mf); for (;;) { char xattr[XATTR_MAXSIZE]; - (void) fread((char *)&node, 1, sizeof(struct modeinfo), mf); - if (feof(mf)) - break; - if (node.xattr) { - (void) fread(xattr, 1, XATTR_MAXSIZE, mf); + if (fread((char *)&node, sizeof(struct modeinfo), 1, mf) != 1) { if (feof(mf)) break; + err(1, "fread"); + } + if (node.xattr) { + if (fread(xattr, XATTR_MAXSIZE, 1, mf) != 1) { + if (feof(mf)) + break; + err(1, "fread"); + } } ep = lookupino(node.ino); if (command == 'i' || command == 'x') { @@ -708,7 +712,8 @@ setdirmodes(int flags) panic("cannot find directory inode %d\n", node.ino); } else { cp = myname(ep); - (void) chown(cp, node.uid, node.gid); + if (chown(cp, node.uid, node.gid) < 0) + warn("chown"); (void) chmod(cp, node.mode); utimes(cp, node.timep); if (node.xattr) @@ -757,13 +762,17 @@ comparedirmodes(void) clearerr(mf); for (;;) { char xattr[XATTR_MAXSIZE]; - (void) fread((char *)&node, 1, sizeof(struct modeinfo), mf); - if (feof(mf)) - break; - if (node.xattr) { - (void) fread(xattr, 1, XATTR_MAXSIZE, mf); + if (fread((char *)&node, sizeof(struct modeinfo), 1, mf) != 1) { if (feof(mf)) break; + err(1, "fread"); + } + if (node.xattr) { + if (fread(xattr, XATTR_MAXSIZE, 1, mf) != 1) { + if (feof(mf)) + break; + err(1, "fread"); + } } ep = lookupino(node.ino); if (ep == NULL) { @@ -928,10 +937,10 @@ savemodeinfo(dump_ino_t ino, struct dinode *dip, char *xattr) { node.uid = dip->di_uid; node.gid = dip->di_gid; node.xattr = xattr ? 1 : 0; - if ( fwrite((char *)&node, 1, sizeof(struct modeinfo), mf) != sizeof(struct modeinfo) ) + if ( fwrite((char *)&node, sizeof(struct modeinfo), 1, mf) != 1 ) err(1,"cannot write to file %s", modefile); if (xattr) - if ( fwrite(xattr, 1, XATTR_MAXSIZE, mf) != XATTR_MAXSIZE) + if ( fwrite(xattr, XATTR_MAXSIZE, 1, mf) != 1 ) err(1,"cannot write to file %s", modefile); } diff --git a/restore/symtab.c b/restore/symtab.c index 7e56057..c3c941e 100644 --- a/restore/symtab.c +++ b/restore/symtab.c @@ -37,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: symtab.c,v 1.27 2005/07/07 09:16:08 stelian Exp $"; + "$Id: symtab.c,v 1.28 2010/06/11 11:19:17 stelian Exp $"; #endif /* not lint */ /* @@ -568,8 +568,8 @@ dumpsymtable(char *filename, long checkpt) for (i = WINO; i <= maxino; i++) { for (ep = lookupino(i); ep != NULL; ep = ep->e_links) { ep->e_index = mynum++; - (void) fwrite(ep->e_name, sizeof(char), - (int)allocsize(ep->e_namlen), fd); + (void) fwrite(ep->e_name, (int)allocsize(ep->e_namlen), + sizeof(char), fd); } } /* @@ -587,7 +587,7 @@ dumpsymtable(char *filename, long checkpt) if (temphash[j]) temphash[j] = (struct entry *)ep->e_entries[j]->e_index; } - fwrite(temphash, dirhash_size, sizeof(struct entry *), fd); + fwrite(temphash, sizeof(struct entry *), dirhash_size, fd); } } } diff --git a/restore/tape.c b/restore/tape.c index 395c99e..45d156f 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -42,7 +42,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.98 2010/06/11 09:57:31 stelian Exp $"; + "$Id: tape.c,v 1.99 2010/06/11 11:19:17 stelian Exp $"; #endif /* not lint */ #include @@ -522,7 +522,8 @@ again: do { fprintf(stderr, "Specify next volume # (none if no more volumes): "); (void) fflush(stderr); - (void) fgets(buf, TP_BSIZE, terminal); + if (!fgets(buf, TP_BSIZE, terminal)) + break; } while (!feof(terminal) && buf[0] == '\n'); if (feof(terminal)) exit(1); @@ -585,7 +586,8 @@ again: fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape); #endif (void) fflush(stderr); - (void) fgets(buf, TP_BSIZE, terminal); + if (fgets(buf, TP_BSIZE, terminal)) + exit(1); if (feof(terminal)) exit(1); if (!strcmp(buf, "none\n")) { @@ -872,8 +874,10 @@ extractfile(struct entry *ep, int doremove) } close(sk); } - (void) chown(name, luid, lgid); - (void) chmod(name, mode); + if (chown(name, luid, lgid) < 0) + warn("%s: chown", name); + if (chmod(name, mode) < 0) + warn("%s: chmod", name); extractattr(name); utimes(name, timep); if (flags) @@ -929,7 +933,8 @@ extractfile(struct entry *ep, int doremove) skipfile(); #ifdef HAVE_LCHOWN - (void) lchown(name, luid, lgid); + if (lchown(name, luid, lgid) < 0) + warn("%s: lchown", name); #endif extractattr(name); return (GOOD); @@ -952,8 +957,10 @@ extractfile(struct entry *ep, int doremove) return (FAIL); } } - (void) chown(name, luid, lgid); - (void) chmod(name, mode); + if (chown(name, luid, lgid) < 0) + warn("%s: chown", name); + if (chmod(name, mode) < 0) + warn("%s: chmod", name); extractattr(name); utimes(name, timep); if (flags) @@ -990,8 +997,10 @@ extractfile(struct entry *ep, int doremove) return (FAIL); } } - (void) chown(name, luid, lgid); - (void) chmod(name, mode); + if (chown(name, luid, lgid) < 0) + warn("%s: chown", name); + if (chmod(name, mode) < 0) + warn("%s: chmod", name); extractattr(name); utimes(name, timep); if (flags) @@ -1039,8 +1048,10 @@ extractfile(struct entry *ep, int doremove) } else skipfile(); - (void) chown(name, luid, lgid); - (void) chmod(name, mode); + if (chown(name, luid, lgid) < 0) + warn("%s: chown", name); + if (chmod(name, mode) < 0) + warn("%s: chmod", name); extractattr(name); utimes(name, timep); if (flags) @@ -1260,8 +1271,10 @@ extractresourceufs(char *name) /* and add the resource data from tape */ getfile(xtrfile, xtrskip); - (void) fchown(ofile, uid, gid); - (void) fchmod(ofile, mode); + if (fchown(ofile, uid, gid) < 0) + warn("%s: fchown", name); + if (fchmod(ofile, mode) < 0) + warn("%s: fchmod", name); (void) close(ofile); utimes(oFileRsrc, timep); (void) lsetflags(oFileRsrc, flags); @@ -1413,7 +1426,8 @@ loop: last_write_was_hole = 1; } if (last_write_was_hole) { - FTRUNCATE(ofile, origsize); + if (FTRUNCATE(ofile, origsize) < 0) + warn("%s: ftruncate", curfile.name); } if (!readingmaps) findinode(&spcl); @@ -2407,8 +2421,8 @@ decompress_tapebuf(struct tapebuf *tpbin, int readsize) } if (reason) { if (lengtherr) - fprintf(stderr, "%s compressed block: %d expected: %u\n", - lengtherr, readsize, tpbin->length + PREFIXSIZE); + fprintf(stderr, "%s compressed block: %d expected: %lu\n", + lengtherr, readsize, (unsigned long)tpbin->length + PREFIXSIZE); fprintf(stderr, "decompression error, block %ld: %s\n", tpblksread+1, reason); if (!cresult) diff --git a/restore/utilities.c b/restore/utilities.c index 4dbc13f..67b223e 100644 --- a/restore/utilities.c +++ b/restore/utilities.c @@ -37,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: utilities.c,v 1.29 2005/07/07 09:16:08 stelian Exp $"; + "$Id: utilities.c,v 1.30 2010/06/11 11:19:17 stelian Exp $"; #endif /* not lint */ #include @@ -488,7 +488,8 @@ panic(fmt, va_alist) return; if (reply("abort") == GOOD) { if (reply("dump core") == GOOD) { - fchdir(wdfd); + if (fchdir(wdfd) < 0) + warn("fchdir"); abort(); } exit(1); diff --git a/restore/xattr.c b/restore/xattr.c index ccc01c1..ddabfa2 100644 --- a/restore/xattr.c +++ b/restore/xattr.c @@ -29,7 +29,7 @@ #ifndef lint static const char rcsid[] = - "$Id: xattr.c,v 1.6 2010/03/08 10:40:52 stelian Exp $"; + "$Id: xattr.c,v 1.7 2010/06/11 11:19:17 stelian Exp $"; #endif /* not lint */ #include @@ -91,9 +91,11 @@ struct ext2_xattr_entry { #define EXT2_XATTR_PAD_BITS 2 #define EXT2_XATTR_PAD (1<e_name_len)) ) @@ -306,7 +308,7 @@ posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size) { if (!buffer) return real_size; if (real_size > size) { - fprintf(stderr, "ACL: not enough space to convert (%d %d)\n", real_size, size); + fprintf(stderr, "ACL: not enough space to convert (%d %d)\n", real_size, (int)size); return -1; } @@ -463,7 +465,7 @@ xattr_cb_compare(char *name, char *value, int valuelen, int isSELinux, void *pri valuesz = strlen(con) + 1; valuef[0] = 0; - strncat(valuef, con, sizeof valuef); + strncat(valuef, con, sizeof(valuef) - 1); freecon(con); } else { @@ -615,7 +617,7 @@ xattr_walk(char *buffer, int (*xattr_cb)(char *, char *, int, int, void *), void if (!transselinuxarg) err = security_canonicalize_context(value, &con); else { - strncat(value, transselinuxarg, sizeof value); + strncat(value, transselinuxarg, sizeof(value) - 1); err = security_canonicalize_context_raw(value, &con); } @@ -626,7 +628,7 @@ xattr_walk(char *buffer, int (*xattr_cb)(char *, char *, int, int, void *), void size = strlen(con) + 1; value[0] = 0; - strncat(value, con, sizeof value); + strncat(value, con, sizeof(value) - 1); freecon(con); } #endif diff --git a/rmt/cipher.c b/rmt/cipher.c index 48da098..8ad219c 100644 --- a/rmt/cipher.c +++ b/rmt/cipher.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,10 @@ cipher(char *buf, int buflen, int do_encrypt) return NULL; } buf[0] = '\0'; - fgets(buf, sizeof buf, fp); + if (!fgets(buf, sizeof buf, fp)) { + syslog(LOG_ERR, "Error reading key file %s: %m", keyfile); + return NULL; + } fclose(fp); i = strlen(buf); if ((i > 0) && diff --git a/rmt/rmt.c b/rmt/rmt.c index 05874a3..863f126 100644 --- a/rmt/rmt.c +++ b/rmt/rmt.c @@ -37,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: rmt.c,v 1.28 2003/11/22 16:52:16 stelian Exp $"; + "$Id: rmt.c,v 1.29 2010/06/11 11:19:18 stelian Exp $"; #endif /* not linux */ /* @@ -310,8 +310,10 @@ top: cp = record; #endif (void)sprintf(resp, "A%lld\n", (long long)rval); - (void)write(1, resp, strlen(resp)); - (void)write(1, cp, rval); + if (write(1, resp, strlen(resp)) != strlen(resp)) + goto ioerror; + if (write(1, cp, rval) != rval) + goto ioerror; block += n >> 10; goto top; @@ -475,13 +477,17 @@ top: mtget.mt_fileno = swaplong(mtget.mt_fileno); mtget.mt_blkno = swaplong(mtget.mt_blkno); (void)sprintf(resp, "A%lld\n", (long long)rval); - (void)write(1, resp, strlen(resp)); - (void)write(1, (char *)&mtget, sizeof (mtget)); + if (write(1, resp, strlen(resp)) != strlen(resp)) + goto ioerror; + if (write(1, (char *)&mtget, sizeof (mtget)) != sizeof(mtget)) + goto ioerror; } else { rval = sizeof (mtget); (void)sprintf(resp, "A%lld\n", (long long)rval); - (void)write(1, resp, strlen(resp)); - (void)write(1, (char *)&mtget, sizeof (mtget)); + if (write(1, resp, strlen(resp)) != strlen(resp)) + goto ioerror; + if (write(1, (char *)&mtget, sizeof (mtget)) != sizeof(mtget)) + goto ioerror; } goto top; } @@ -546,7 +552,8 @@ top: respond: DEBUG1("rmtd: A %lld\n", (long long)rval); (void)sprintf(resp, "A%lld\n", (long long)rval); - (void)write(1, resp, strlen(resp)); + if (write(1, resp, strlen(resp)) != strlen(resp)) + goto ioerror; goto top; ioerror: error(errno); @@ -593,7 +600,8 @@ error(int num) DEBUG2("rmtd: E %d (%s)\n", num, strerror(num)); (void)snprintf(resp, sizeof(resp), "E%d\n%s\n", num, strerror(num)); - (void)write(1, resp, strlen(resp)); + if (write(1, resp, strlen(resp)) != strlen(resp)) + DEBUG("rmtd: write error\n"); } static unsigned long -- 2.39.2