From cb4ed1a3752b54c323824e7455e68e4b808e220a Mon Sep 17 00:00:00 2001 From: claudiol Date: Tue, 28 Aug 2018 12:46:52 -0400 Subject: [PATCH] [3298] Compile warnings fixed --- Makefile | 2 +- block-qcow.c | 25 +++++++++++++++++++++---- block-raw.c | 17 ++++++++++++----- block-vvfat.c | 14 ++++++++++---- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index e1f7e52..a2821f2 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ CC += $(shell if [ "`uname -m`" = "sparc64" -o "`uname -m`" = "sun4u" ]; then ec COCOA_LIBS=$(shell if [ "`uname -s`" = "Darwin" ]; then echo "-F/System/Library/Frameworks -framework Cocoa -framework IOKit"; fi) -CFLAGS = -O2 -Wall -Werror -Wno-unused-result $(DEBUG) $(INCLUDES) $(DEFINES) +CFLAGS = -O2 -Wall -Werror -D_FORTIFY_SOURCE=1 $(DEBUG) $(INCLUDES) $(DEFINES) LDFLAGS = $(DEBUG) $(X49GP_LDFLAGS) $(GDB_LDFLAGS) LDLIBS = $(X49GP_LIBS) $(GDB_LIBS) $(COCOA_LIBS) diff --git a/block-qcow.c b/block-qcow.c index 693b50f..ca3ad2b 100644 --- a/block-qcow.c +++ b/block-qcow.c @@ -436,6 +436,7 @@ static int qcow_create(const char *filename, int64_t total_size, int fd, header_size, backing_filename_len, l1_size, i, shift; QCowHeader header; uint64_t tmp; + int ret; fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (fd < 0) @@ -471,17 +472,33 @@ static int qcow_create(const char *filename, int64_t total_size, } /* write all the data */ - write(fd, &header, sizeof(header)); + ret = write(fd, &header, sizeof(header)); + if (ret != sizeof(header)) { + ret = -1; + goto exit; + } + if (backing_file) { - write(fd, backing_file, backing_filename_len); + ret = write(fd, backing_file, backing_filename_len); + if (ret != backing_filename_len) { + ret = -1; + goto exit; + } } lseek(fd, header_size, SEEK_SET); tmp = 0; for(i = 0;i < l1_size; i++) { - write(fd, &tmp, sizeof(tmp)); + ret = write(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -1; + goto exit; + } } + + ret = 0; +exit: close(fd); - return 0; + return ret; } static int qcow_make_empty(BlockDriverState *bs) diff --git a/block-raw.c b/block-raw.c index 2f1796e..adfeec8 100644 --- a/block-raw.c +++ b/block-raw.c @@ -227,17 +227,24 @@ static int raw_create(const char *filename, int64_t total_size, const char *backing_file, int flags) { int fd; + int result = 0; if (flags || backing_file) return -ENOTSUP; fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); - if (fd < 0) - return -EIO; - ftruncate(fd, total_size * 512); - close(fd); - return 0; + if (fd < 0) { + result=-errno; + } else { + if (ftruncate(fd, total_size * 512)) { + result=-errno; + } + if (close(fd) != 0) { + result=-errno; + } + } + return result; } static void raw_flush(BlockDriverState *bs) diff --git a/block-vvfat.c b/block-vvfat.c index e95e386..edc10a4 100644 --- a/block-vvfat.c +++ b/block-vvfat.c @@ -888,11 +888,14 @@ static int init_directories(BDRVVVFATState* s, stat(dirname, &st); entry = array_get_next(&(s->directory)); entry->attributes = 0x08; /* archive | volume label */ - memset(entry->name, ' ', 11); + memset(entry->name, ' ', 8); + memset(entry->extension, ' ', 3); namelen = strlen(VOLUME_LABEL); if (namelen > 11) namelen = 11; - memcpy(entry->name, VOLUME_LABEL, namelen); + memcpy(entry->name, VOLUME_LABEL, namelen > 8 ? 8 : namelen); + if (namelen > 8) + memcpy(entry->extension, VOLUME_LABEL+8, namelen-8); entry->reserved[0] = entry->reserved[1] = 0; entry->ctime = fat_datetime(st.st_ctime, 1); entry->cdate = fat_datetime(st.st_ctime, 0); @@ -2353,8 +2356,11 @@ static int commit_one_file(BDRVVVFATState* s, c = c1; } - ftruncate(fd, size); - close(fd); + if (ftruncate(fd, size)) { + perror("ftruncate()"); + close(fd); + return -4; + } return commit_mappings(s, first_cluster, dir_index); }