From 0e5b68e0159e071dae2cac01c2b6783b8e926133 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Thu, 26 Aug 2010 09:52:40 -0700 Subject: [PATCH] Fix gcc fortify source warnings Resolve issues uncovered by -D_FORTIFY_SOURCE=2, the default redhat macro's file adds this option to the cflags. This causes warnings of the following type designed to keep the developer honest: warning: ignoring return value of 'foo', declared with attribute warn_unused_result The short term fix is to wrap these calls in VERIFY() to check the return code. The code was already assusing these would never fail. Signed-off-by: Brian Behlendorf --- cmd/zdb/zdb.c | 6 +++--- cmd/ztest/ztest.c | 5 +++-- lib/libzpool/kernel.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 891cb9c..012d009 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -1668,7 +1668,7 @@ dump_uberblock(uberblock_t *ub, const char *header, const char *footer) { time_t timestamp = ub->ub_timestamp; - (void) printf(header ? header : ""); + (void) printf("%s", header ? header : ""); (void) printf("\tmagic = %016llx\n", (u_longlong_t)ub->ub_magic); (void) printf("\tversion = %llu\n", (u_longlong_t)ub->ub_version); (void) printf("\ttxg = %llu\n", (u_longlong_t)ub->ub_txg); @@ -1680,7 +1680,7 @@ dump_uberblock(uberblock_t *ub, const char *header, const char *footer) sprintf_blkptr(blkbuf, &ub->ub_rootbp); (void) printf("\trootbp = %s\n", blkbuf); } - (void) printf(footer ? footer : ""); + (void) printf("%s", footer ? footer : ""); } static void @@ -2554,7 +2554,7 @@ zdb_dump_block_raw(void *buf, uint64_t size, int flags) { if (flags & ZDB_FLAG_BSWAP) byteswap_uint64_array(buf, size); - (void) write(1, buf, size); + VERIFY(write(fileno(stdout), buf, size) == size); } static void diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c index 771f142..5e21e62 100644 --- a/cmd/ztest/ztest.c +++ b/cmd/ztest/ztest.c @@ -2592,7 +2592,7 @@ grow_vdev(vdev_t *vd, void *arg) return (vd); fsize = lseek(fd, 0, SEEK_END); - (void) ftruncate(fd, *newsize); + VERIFY(ftruncate(fd, *newsize) == 0); if (zopt_verbose >= 6) { (void) printf("%s grew from %lu to %lu bytes\n", @@ -5459,7 +5459,8 @@ main(int argc, char **argv) process_options(argc, argv); /* Override location of zpool.cache */ - (void) asprintf((char **)&spa_config_path, "%s/zpool.cache", zopt_dir); + VERIFY(asprintf((char **)&spa_config_path, "%s/zpool.cache", + zopt_dir) != -1); /* * Blow away any existing copy of zpool.cache diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index f323bf6..ef26406 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -796,7 +796,7 @@ umem_out_of_memory(void) { char errmsg[] = "out of memory -- generating core dump\n"; - write(fileno(stderr), errmsg, sizeof (errmsg)); + (void) fprintf(stderr, "%s", errmsg); abort(); return (0); } -- 1.8.3.1