Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MGPNl-0000W1-KG for qemu-devel@nongnu.org; Mon, 15 Jun 2009 23:30:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MGPNh-0000V2-FZ for qemu-devel@nongnu.org; Mon, 15 Jun 2009 23:30:45 -0400 Received: from [199.232.76.173] (port=35005 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MGPNh-0000Uw-4t for qemu-devel@nongnu.org; Mon, 15 Jun 2009 23:30:41 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:54661) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MGPNf-00023C-VT for qemu-devel@nongnu.org; Mon, 15 Jun 2009 23:30:40 -0400 Received: from smtp1-g21.free.fr (localhost [127.0.0.1]) by smtp1-g21.free.fr (Postfix) with ESMTP id 98B6694005C for ; Tue, 16 Jun 2009 05:30:35 +0200 (CEST) Received: from jcd-desktop.localnet (unknown [78.235.240.156]) by smtp1-g21.free.fr (Postfix) with ESMTP id 4E9A394009B for ; Tue, 16 Jun 2009 05:30:32 +0200 (CEST) From: "Jean-Christophe Dubois" Date: Tue, 16 Jun 2009 05:30:36 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <200906160530.37086.jcd@tribudubois.net> Subject: [Qemu-devel] [PATCH] avoid compilation warning/errors on up to date compilers List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel Some system calls are now requiring to have their return value checked. Without this a warning is emited and in the case a qemu an error is triggered as qemu is considering warnings as errors. =46or example: block/cow.c: In function =E2=80=98cow_create=E2=80=99: block/cow.c:251: error: ignoring return value of =E2=80=98write=E2=80=99, d= eclared with=20 attribute warn_unused_result block/cow.c:253: error: ignoring return value of =E2=80=98ftruncate=E2=80= =99, declared=20 with attribute warn_unused_result This is an attempt at removing all these warnings to allow a clean compilation with up to date compilers/distributions. Signed-off-by: Jean-Christophe DUBOIS =2D-- block.c | 3 ++- block/bochs.c | 3 ++- block/cow.c | 14 +++++++++++--- block/qcow.c | 22 ++++++++++++++++------ block/qcow2.c | 37 +++++++++++++++++++++++++++++-------- block/raw-posix.c | 9 ++++++--- block/vmdk.c | 38 ++++++++++++++++++++++++++++---------- block/vvfat.c | 26 +++++++++++++++++++------- linux-user/mmap.c | 7 +++++-- linux-user/path.c | 6 +++++- osdep.c | 5 ++++- qemu-nbd.c | 3 ++- slirp/misc.c | 3 ++- usb-linux.c | 3 +-- vl.c | 12 ++++++++---- 15 files changed, 140 insertions(+), 51 deletions(-) diff --git a/block.c b/block.c index e6b91c6..28edf4d 100644 =2D-- a/block.c +++ b/block.c @@ -368,7 +368,8 @@ int bdrv_open2(BlockDriverState *bs, const char *filena= me, int flags, snprintf(backing_filename, sizeof(backing_filename), "%s", filename); else =2D realpath(filename, backing_filename); + if (!realpath(filename, backing_filename)) + return -1; =20 bdrv_qcow2 =3D bdrv_find_format("qcow2"); options =3D parse_option_parameters("", bdrv_qcow2->create_options= , NULL); diff --git a/block/bochs.c b/block/bochs.c index bac81c4..c80b86e 100644 =2D-- a/block/bochs.c +++ b/block/bochs.c @@ -199,7 +199,8 @@ static inline int seek_to_sector(BlockDriverState *bs, = int64_t sector_num) // read in bitmap for current extent lseek(s->fd, bitmap_offset + (extent_offset / 8), SEEK_SET); =20 =2D read(s->fd, &bitmap_entry, 1); + if (read(s->fd, &bitmap_entry, 1) !=3D 1) + return -1; // not allocated =20 if (!((bitmap_entry >> (extent_offset % 8)) & 1)) { diff --git a/block/cow.c b/block/cow.c index 84818f1..0893ec1 100644 =2D-- a/block/cow.c +++ b/block/cow.c @@ -248,11 +248,19 @@ static int cow_create(const char *filename, QEMUOptio= nParameter *options) } cow_header.sectorsize =3D cpu_to_be32(512); cow_header.size =3D cpu_to_be64(image_sectors * 512); =2D write(cow_fd, &cow_header, sizeof(cow_header)); + if (write(cow_fd, &cow_header, sizeof(cow_header)) =3D=3D sizeof(cow_h= eader)) + goto fail; + /* resize to include at least all the bitmap */ =2D ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3)); + if (ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3))) + goto fail; + close(cow_fd); return 0; + +fail: + close(cow_fd); + return -1; } =20 static void cow_flush(BlockDriverState *bs) diff --git a/block/qcow.c b/block/qcow.c index 55a68a6..fc581ec 100644 =2D-- a/block/qcow.c +++ b/block/qcow.c @@ -801,17 +801,27 @@ static int qcow_create(const char *filename, QEMUOpti= onParameter *options) } =20 /* write all the data */ =2D write(fd, &header, sizeof(header)); =2D if (backing_file) { =2D write(fd, backing_file, backing_filename_len); =2D } =2D lseek(fd, header_size, SEEK_SET); + if (write(fd, &header, sizeof(header)) !=3D sizeof(header)) + goto fail; + + if (backing_file) + if (write(fd, backing_file, backing_filename_len) !=3D backing_fil= ename_len) + goto fail; + + if (lseek(fd, header_size, SEEK_SET) =3D=3D -1) + goto fail; tmp =3D 0; for(i =3D 0;i < l1_size; i++) { =2D write(fd, &tmp, sizeof(tmp)); + if (write(fd, &tmp, sizeof(tmp)) !=3D sizeof(tmp)) + goto fail; } + close(fd); return 0; + +fail: + close(fd); + return -1; } =20 static int qcow_make_empty(BlockDriverState *bs) diff --git a/block/qcow2.c b/block/qcow2.c index c2be42e..7ee7e62 100644 =2D-- a/block/qcow2.c +++ b/block/qcow2.c @@ -1663,7 +1663,9 @@ static int qcow_create2(const char *filename, int64_t= total_size, create_refcount_update(s, s->refcount_block_offset, ref_clusters * s->= cluster_size); =20 /* write all the data */ =2D write(fd, &header, sizeof(header)); + if (write(fd, &header, sizeof(header)) !=3D sizeof(header)) + goto fail; + if (backing_file) { if (backing_format_len) { char zero[16]; @@ -1672,29 +1674,48 @@ static int qcow_create2(const char *filename, int64= _t total_size, memset(zero, 0, sizeof(zero)); cpu_to_be32s(&ext_bf.magic); cpu_to_be32s(&ext_bf.len); =2D write(fd, &ext_bf, sizeof(ext_bf)); =2D write(fd, backing_format, backing_format_len); + if (write(fd, &ext_bf, sizeof(ext_bf)) !=3D sizeof(ext_bf)) + goto fail; + + if (write(fd, backing_format, backing_format_len) !=3D backing= _format_len) + goto fail; + if (d>0) { =2D write(fd, zero, d); + if (write(fd, zero, d) !=3D d) + goto fail; } } =2D write(fd, backing_file, backing_filename_len); + if (write(fd, backing_file, backing_filename_len) !=3D backing_fil= ename_len) + goto fail; } lseek(fd, s->l1_table_offset, SEEK_SET); tmp =3D 0; for(i =3D 0;i < l1_size; i++) { =2D write(fd, &tmp, sizeof(tmp)); + if (write(fd, &tmp, sizeof(tmp)) !=3D sizeof(tmp)) + goto fail; } lseek(fd, s->refcount_table_offset, SEEK_SET); =2D write(fd, s->refcount_table, s->cluster_size); + if (write(fd, s->refcount_table, s->cluster_size) !=3D s->cluster_size) + goto fail; =20 lseek(fd, s->refcount_block_offset, SEEK_SET); =2D write(fd, s->refcount_block, ref_clusters * s->cluster_size); + if (write(fd, s->refcount_block, ref_clusters * s->cluster_size) !=3D = ref_clusters * s->cluster_size) + goto fail; =20 qemu_free(s->refcount_table); + s->refcount_table =3D NULL; qemu_free(s->refcount_block); + s->refcount_block =3D NULL; close(fd); return 0; + +fail: + qemu_free(s->refcount_table); + s->refcount_table =3D NULL; + qemu_free(s->refcount_block); + s->refcount_block =3D NULL; + close(fd); + return -1; } =20 static int qcow_create(const char *filename, QEMUOptionParameter *options) diff --git a/block/raw-posix.c b/block/raw-posix.c index 4798d62..14119f1 100644 =2D-- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -552,7 +552,8 @@ static void aio_signal_handler(int signum) if (posix_aio_state) { char byte =3D 0; =20 =2D write(posix_aio_state->wfd, &byte, sizeof(byte)); + if (write(posix_aio_state->wfd, &byte, sizeof(byte)) !=3D sizeof(b= yte)) + fprintf(stderr, "failed to write to posix_aio_state\n"); } =20 qemu_service_io(); @@ -832,6 +833,7 @@ static int raw_create(const char *filename, QEMUOptionP= arameter *options) { int fd; int64_t total_size =3D 0; + int ret =3D 0; =20 /* Read out options */ while (options && options->name) { @@ -845,9 +847,10 @@ static int raw_create(const char *filename, QEMUOption= Parameter *options) 0644); if (fd < 0) return -EIO; =2D ftruncate(fd, total_size * 512); + if (ftruncate(fd, total_size * 512)) + ret =3D -1; close(fd); =2D return 0; + return ret; } =20 static void raw_flush(BlockDriverState *bs) diff --git a/block/vmdk.c b/block/vmdk.c index f21f02b..136d11b 100644 =2D-- a/block/vmdk.c +++ b/block/vmdk.c @@ -233,7 +233,8 @@ static int vmdk_snapshot_create(const char *filename, c= onst char *backing_file) memset(&header, 0, sizeof(header)); memcpy(&header,&hdr[4], sizeof(header)); // skip the VMDK4_MAGIC =20 =2D ftruncate(snp_fd, header.grain_offset << 9); + if (ftruncate(snp_fd, header.grain_offset << 9)) + goto fail; /* the descriptor offset =3D 0x200 */ if (lseek(p_fd, 0x200, SEEK_SET) =3D=3D -1) goto fail; @@ -771,22 +772,32 @@ static int vmdk_create(const char *filename, QEMUOpti= onParameter *options) header.check_bytes[3] =3D 0xa; =20 /* write all the data */ =2D write(fd, &magic, sizeof(magic)); =2D write(fd, &header, sizeof(header)); + if (write(fd, &magic, sizeof(magic)) !=3D sizeof(magic)) + goto fail; =20 =2D ftruncate(fd, header.grain_offset << 9); + if (write(fd, &header, sizeof(header)) !=3D sizeof(header)) + goto fail; + + if (ftruncate(fd, header.grain_offset << 9)) + goto fail; =20 /* write grain directory */ =2D lseek(fd, le64_to_cpu(header.rgd_offset) << 9, SEEK_SET); + if (lseek(fd, le64_to_cpu(header.rgd_offset) << 9, SEEK_SET) =3D=3D -1) + goto fail; + for (i =3D 0, tmp =3D header.rgd_offset + gd_size; i < gt_count; i++, tmp +=3D gt_size) =2D write(fd, &tmp, sizeof(tmp)); + if (write(fd, &tmp, sizeof(tmp)) !=3D sizeof(tmp)) + goto fail; =20 /* write backup grain directory */ =2D lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET); + if (lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET) =3D=3D -1) + goto fail; + for (i =3D 0, tmp =3D header.gd_offset + gd_size; i < gt_count; i++, tmp +=3D gt_size) =2D write(fd, &tmp, sizeof(tmp)); + if (write(fd, &tmp, sizeof(tmp)) !=3D sizeof(tmp)) + goto fail; =20 /* compose the descriptor */ real_filename =3D filename; @@ -802,11 +813,18 @@ static int vmdk_create(const char *filename, QEMUOpti= onParameter *options) total_size / (int64_t)(63 * 16)); =20 /* write the descriptor */ =2D lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET); =2D write(fd, desc, strlen(desc)); + if (lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET) =3D=3D -= 1) + goto fail; + + if (write(fd, desc, strlen(desc)) !=3D strlen(desc)) + goto fail; =20 close(fd); return 0; + +fail: + close(fd); + return -1; } =20 static void vmdk_close(BlockDriverState *bs) diff --git a/block/vvfat.c b/block/vvfat.c index 1e37b9f..c4ac9b9 100644 =2D-- a/block/vvfat.c +++ b/block/vvfat.c @@ -2215,6 +2215,7 @@ static int commit_one_file(BDRVVVFATState* s, char* cluster =3D qemu_malloc(s->cluster_size); uint32_t i; int fd =3D 0; + int ret =3D 0; =20 assert(offset < size); assert((offset % s->cluster_size) =3D=3D 0); @@ -2229,14 +2230,15 @@ static int commit_one_file(BDRVVVFATState* s, return fd; } if (offset > 0) =2D if (lseek(fd, offset, SEEK_SET) !=3D offset) =2D return -3; + if (lseek(fd, offset, SEEK_SET) !=3D offset) { + ret =3D -3; + goto fail; + } =20 while (offset < size) { uint32_t c1; int rest_size =3D (size - offset > s->cluster_size ? s->cluster_size : size - offset); =2D int ret; =20 c1 =3D modified_fat_get(s, c); =20 @@ -2247,19 +2249,29 @@ static int commit_one_file(BDRVVVFATState* s, (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200); =20 if (ret < 0) =2D return ret; + goto fail; =20 =2D if (write(fd, cluster, rest_size) < 0) =2D return -2; + if (write(fd, cluster, rest_size) < 0) { + ret =3D -2; + goto fail; + } =20 offset +=3D rest_size; c =3D c1; } =20 =2D ftruncate(fd, size); + if (ftruncate(fd, size)) { + ret =3D -1; + goto fail; + } + close(fd); =20 return commit_mappings(s, first_cluster, dir_index); + +fail: + close(fd); + return ret; } =20 #ifdef DEBUG diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 6f300a0..a5b069e 100644 =2D-- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -252,7 +252,8 @@ static int mmap_frag(abi_ulong real_start, mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); =20 /* read the corresponding file data */ =2D pread(fd, g2h(start), end - start, offset); + if (pread(fd, g2h(start), end - start, offset) =3D=3D -1) + return -1; =20 /* put final protection */ if (prot_new !=3D (prot1 | PROT_WRITE)) @@ -469,7 +470,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, -1, 0); if (retaddr =3D=3D -1) goto fail; =2D pread(fd, g2h(start), len, offset); + if (pread(fd, g2h(start), len, offset) =3D=3D -1) + goto fail; + =20 if (!(prot & PROT_WRITE)) { ret =3D target_mprotect(start, len, prot); if (ret !=3D 0) { diff --git a/linux-user/path.c b/linux-user/path.c index 06b1f5f..f716122 100644 =2D-- a/linux-user/path.c +++ b/linux-user/path.c @@ -45,8 +45,12 @@ static struct pathelem *new_entry(const char *root, { struct pathelem *new =3D malloc(sizeof(*new)); new->name =3D strdup(name); =2D asprintf(&new->pathname, "%s/%s", root, name); new->num_entries =3D 0; + if (asprintf(&new->pathname, "%s/%s", root, name) =3D=3D -1) { + free(new->name); + free(new); + new =3D NULL; + } return new; } =20 diff --git a/osdep.c b/osdep.c index b300ba1..de0124e 100644 =2D-- a/osdep.c +++ b/osdep.c @@ -160,7 +160,10 @@ static void *kqemu_vmalloc(size_t size) unlink(phys_ram_file); } size =3D (size + 4095) & ~4095; =2D ftruncate(phys_ram_fd, phys_ram_size + size); + if (ftruncate(phys_ram_fd, phys_ram_size + size)) { + fprintf(stderr, "Could not truncate phys_ram_file\n"); + exit(1); + } #endif /* !(__OpenBSD__ || __FreeBSD__ || __DragonFly__) */ ptr =3D mmap(NULL, size, diff --git a/qemu-nbd.c b/qemu-nbd.c index 0af97ca..0a8d85f 100644 =2D-- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -346,7 +346,8 @@ int main(int argc, char **argv) int sock; =20 if (!verbose) =2D daemon(0, 0); /* detach client and server */ + if (daemon(0, 0)) /* detach client and server */ + errx(errno, "Could not detach client and server"); =20 if (socket =3D=3D NULL) { sprintf(sockpath, SOCKET_PATH, basename(device)); diff --git a/slirp/misc.c b/slirp/misc.c index 1391d49..e09cb8a 100644 =2D-- a/slirp/misc.c +++ b/slirp/misc.c @@ -365,7 +365,8 @@ fork_exec(struct socket *so, const char *ex, int do_pty) snprintf(buff, sizeof(buff), "Error: execvp of %s failed: %s\n", argv[0], strerror(errno)); =2D write(2, buff, strlen(buff)+1); + if (write(2, buff, strlen(buff)+1) !=3D strlen(buff)+1) + lprint("Error: failed to write to stderr: %s\n", strerror(errno)); } close(0); close(1); close(2); /* XXX */ exit(1); diff --git a/usb-linux.c b/usb-linux.c index 67e4acd..d71c4b5 100644 =2D-- a/usb-linux.c +++ b/usb-linux.c @@ -1159,9 +1159,8 @@ static int usb_host_read_file(char *line, size_t line= _size, const char *device_f device_file); f =3D fopen(filename, "r"); if (f) { =2D fgets(line, line_size, f); + if (fgets(line, line_size, f)) ret =3D 1; fclose(f); =2D ret =3D 1; } else { monitor_printf(mon, "husb: could not open %s\n", filename); } diff --git a/vl.c b/vl.c index bdd78cf..6750f9d 100644 =2D-- a/vl.c +++ b/vl.c @@ -3691,7 +3691,8 @@ static void qemu_event_increment(void) if (io_thread_fd =3D=3D -1) return; =20 =2D write(io_thread_fd, &byte, sizeof(byte)); + if (write(io_thread_fd, &byte, sizeof(byte)) !=3D sizeof(byte)) + perror("Failed write"); } =20 static void qemu_event_read(void *opaque) @@ -5766,7 +5767,8 @@ int main(int argc, char **argv, char **envp) if (pid_file && qemu_create_pidfile(pid_file) !=3D 0) { if (daemonize) { uint8_t status =3D 1; =2D write(fds[1], &status, 1); + if (write(fds[1], &status, 1) !=3D 1) + fprintf(stderr, "Could not write status to pid file \n"); } else fprintf(stderr, "Could not acquire pid file\n"); exit(1); @@ -6203,7 +6205,8 @@ int main(int argc, char **argv, char **envp) if (len !=3D 1) exit(1); =20 =2D chdir("/"); + if (chdir("/")) + exit(1); TFR(fd =3D open("/dev/null", O_RDWR)); if (fd =3D=3D -1) exit(1); @@ -6222,7 +6225,8 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "chroot failed\n"); exit(1); } =2D chdir("/"); + if (chdir("/")) + exit(1); } =20 if (run_as) {