From c8f0aa726c9eacf00d01bdef0b04463bf4bf4c6a Mon Sep 17 00:00:00 2001
From: Juan Quintela <quintela@redhat.com>
Date: Thu, 4 Mar 2010 23:11:42 -0300
Subject: [PATCH 20/42] fix qemu-kvm _FORTIFY_SOURCE compilation

RH-Author: Juan Quintela <quintela@redhat.com>
Message-id: <548c9022694c56e4d569156ab42596ff8b4dcd40.1267743950.git.quintela@redhat.com>
Patchwork-id: 7548
O-Subject: [PATCH 20/32] fix qemu-kvm _FORTIFY_SOURCE compilation
Bugzilla: 567099
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com>

It is part of merge commit:
commit c23dcd150c926154c8a6fd942c1672828b789460
Merge: c3aa441 163c8a5
Author: Marcelo Tosatti <mtosatti@redhat.com>
Date:   Sun Jan 31 23:38:30 2010 -0200

    Merge commit '163c8a59f6f9c370b74a81856194757e3773b358' into upstream-merge
Signed-of-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 exec.c                 |    4 +++-
 hw/device-assignment.c |    6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 exec.c                 |    4 +++-
 hw/device-assignment.c |    6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/exec.c b/exec.c
index 8f873ab..de4345b 100644
--- a/exec.c
+++ b/exec.c
@@ -2498,7 +2498,9 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path)
      * If anything goes wrong with it under other filesystems,
      * mmap will fail.
      */
-    ftruncate(fd, memory);
+    if (ftruncate(fd, memory)) {
+        perror("ftruncate");
+    }
 
 #ifdef MAP_POPULATE
     /* NB: MAP_POPULATE won't exhaustively alloc all phys pages in the case
diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index fb04047..04c6538 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -1388,7 +1388,7 @@ static void scan_option_rom(const char *name, uint8_t devfn, void *roms)
  */
 static void assigned_dev_load_option_rom(AssignedDevice *dev)
 {
-    int size, len;
+    int size, len, ret;
     void *buf;
     FILE *fp;
     uint8_t i = 1;
@@ -1425,8 +1425,8 @@ static void assigned_dev_load_option_rom(AssignedDevice *dev)
         return;
     }
 
-    fread(buf, size, 1, fp);
-    if (!feof(fp) || ferror(fp)) {
+    ret = fread(buf, size, 1, fp);
+    if (!feof(fp) || ferror(fp) || ret != 1) {
         free(buf);
         fclose(fp);
         return;
-- 
1.6.3.rc4.29.g8146

