diff mbox

[06/14] block/vvfat.c: fix warnings with _FORTIFY_SOURCE

Message ID 1262223199-19062-6-git-send-email-kirill@shutemov.name
State New
Headers show

Commit Message

Kirill A . Shutemov Dec. 31, 2009, 1:33 a.m. UTC
CC    block/vvfat.o
cc1: warnings being treated as errors
block/vvfat.c: In function 'commit_one_file':
block/vvfat.c:2259: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result
make: *** [block/vvfat.o] Error 1
  CC    block/vvfat.o
In file included from /usr/include/stdio.h:912,
                 from ./qemu-common.h:19,
                 from block/vvfat.c:27:
In function 'snprintf',
    inlined from 'init_directories' at block/vvfat.c:871,
    inlined from 'vvfat_open' at block/vvfat.c:1068:
/usr/include/bits/stdio2.h:65: error: call to __builtin___snprintf_chk will always overflow destination buffer
make: *** [block/vvfat.o] Error 1

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 block/vvfat.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

Comments

Paolo Bonzini Dec. 31, 2009, 7:55 a.m. UTC | #1
On 12/31/2009 02:33 AM, Kirill A. Shutemov wrote:
> +	snprintf((char*)entry->name,8,"QEMU VV");
> +	snprintf((char*)entry->extension,3,"FAT");

Wrong, the split should be "QEMU VVF" and "AT".  Even better, change it 
to "QEMU VVF" and "AT " with a trailing space and use memcpy since it's 
not a NULL-terminated name.

Paolo
diff mbox

Patch

diff --git a/block/vvfat.c b/block/vvfat.c
index 063f731..a7ec6b7 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -868,7 +868,8 @@  static int init_directories(BDRVVVFATState* s,
     {
 	direntry_t* entry=array_get_next(&(s->directory));
 	entry->attributes=0x28; /* archive | volume label */
-	snprintf((char*)entry->name,11,"QEMU VVFAT");
+	snprintf((char*)entry->name,8,"QEMU VV");
+	snprintf((char*)entry->extension,3,"FAT");
     }
 
     /* Now build FAT, and write back information into directory */
@@ -2256,7 +2257,10 @@  static int commit_one_file(BDRVVVFATState* s,
 	c = c1;
     }
 
-    ftruncate(fd, size);
+    if (ftruncate(fd, size)) {
+	perror("ftruncate()");
+	abort();
+    }
     close(fd);
 
     return commit_mappings(s, first_cluster, dir_index);