Skip to contentSkip to conversation

[6792] fread_targphys(): Do not cut off the tail.

Qemu-devel Blue Swirl 1 participant 1 message Mar 9, 2009

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

Revision: 6792

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6792
Author:   blueswir1
Date:     2009-03-09 18:08:56 +0000 (Mon, 09 Mar 2009)

Log Message:
-----------
fread_targphys(): Do not cut off the tail.

loader.c:fread_targphys() read file by 4096 byte chunks and store them to memory. But did not store the last chunk if its size was not 4096.

Modified Paths:
--------------
trunk/loader.c

Modified: trunk/loader.c
===================================================================

loader.c +2 -1
@@ -90,11 +90,12 @@
     while (nbytes) {
 	want = nbytes > sizeof(buf) ? sizeof(buf) : nbytes;
 	did = fread(buf, 1, want, f);
-	if (did != want) break;
 
 	cpu_physical_memory_write_rom(dst_addr, buf, did);
 	dst_addr += did;
 	nbytes -= did;
+	if (did != want)
+	    break;
     }
     return dst_addr - dst_begin;
 }