[3298] Compile warnings fixed

This commit is contained in:
claudiol 2018-08-28 12:46:52 -04:00
parent c3ed313cf7
commit cb4ed1a375
4 changed files with 44 additions and 14 deletions

View file

@ -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) 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) LDFLAGS = $(DEBUG) $(X49GP_LDFLAGS) $(GDB_LDFLAGS)
LDLIBS = $(X49GP_LIBS) $(GDB_LIBS) $(COCOA_LIBS) LDLIBS = $(X49GP_LIBS) $(GDB_LIBS) $(COCOA_LIBS)

View file

@ -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; int fd, header_size, backing_filename_len, l1_size, i, shift;
QCowHeader header; QCowHeader header;
uint64_t tmp; uint64_t tmp;
int ret;
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (fd < 0) if (fd < 0)
@ -471,17 +472,33 @@ static int qcow_create(const char *filename, int64_t total_size,
} }
/* write all the data */ /* 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) { 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); lseek(fd, header_size, SEEK_SET);
tmp = 0; tmp = 0;
for(i = 0;i < l1_size; i++) { 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); close(fd);
return 0; return ret;
} }
static int qcow_make_empty(BlockDriverState *bs) static int qcow_make_empty(BlockDriverState *bs)

View file

@ -227,17 +227,24 @@ static int raw_create(const char *filename, int64_t total_size,
const char *backing_file, int flags) const char *backing_file, int flags)
{ {
int fd; int fd;
int result = 0;
if (flags || backing_file) if (flags || backing_file)
return -ENOTSUP; return -ENOTSUP;
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644); 0644);
if (fd < 0) if (fd < 0) {
return -EIO; result=-errno;
ftruncate(fd, total_size * 512); } else {
close(fd); if (ftruncate(fd, total_size * 512)) {
return 0; result=-errno;
}
if (close(fd) != 0) {
result=-errno;
}
}
return result;
} }
static void raw_flush(BlockDriverState *bs) static void raw_flush(BlockDriverState *bs)

View file

@ -888,11 +888,14 @@ static int init_directories(BDRVVVFATState* s,
stat(dirname, &st); stat(dirname, &st);
entry = array_get_next(&(s->directory)); entry = array_get_next(&(s->directory));
entry->attributes = 0x08; /* archive | volume label */ entry->attributes = 0x08; /* archive | volume label */
memset(entry->name, ' ', 11); memset(entry->name, ' ', 8);
memset(entry->extension, ' ', 3);
namelen = strlen(VOLUME_LABEL); namelen = strlen(VOLUME_LABEL);
if (namelen > 11) if (namelen > 11)
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->reserved[0] = entry->reserved[1] = 0;
entry->ctime = fat_datetime(st.st_ctime, 1); entry->ctime = fat_datetime(st.st_ctime, 1);
entry->cdate = fat_datetime(st.st_ctime, 0); entry->cdate = fat_datetime(st.st_ctime, 0);
@ -2353,8 +2356,11 @@ static int commit_one_file(BDRVVVFATState* s,
c = c1; c = c1;
} }
ftruncate(fd, size); if (ftruncate(fd, size)) {
close(fd); perror("ftruncate()");
close(fd);
return -4;
}
return commit_mappings(s, first_cluster, dir_index); return commit_mappings(s, first_cluster, dir_index);
} }