diff mbox

[3/5] savevm: define qemu_get_byte() using qemu_peek_byte()

Message ID 49696d43bab6d485d414cfe58772c9ac54926b63.1317911543.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Oct. 6, 2011, 4:21 p.m. UTC
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 savevm.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

Comments

Paolo Bonzini Oct. 6, 2011, 4:26 p.m. UTC | #1
On 10/06/2011 06:21 PM, Juan Quintela wrote:
> +    result = qemu_peek_byte(f);
> +
> +    if (f->buf_index<  f->buf_size) {
> +        f->buf_index++;
>       }

This should really be an assert that f->buf_index < f->buf_size, 
otherwise qemu_peek_byte has read garbage.

Paolo
Juan Quintela Oct. 6, 2011, 10:40 p.m. UTC | #2
Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 10/06/2011 06:21 PM, Juan Quintela wrote:
>> +    result = qemu_peek_byte(f);
>> +
>> +    if (f->buf_index<  f->buf_size) {
>> +        f->buf_index++;
>>       }
>
> This should really be an assert that f->buf_index < f->buf_size,
> otherwise qemu_peek_byte has read garbage.

That is a change from current behaviour.  qemu_get_byte() returns 0 in
the case that there is nothing to read.  Yes, it is ugly.

Later, Juan.
diff mbox

Patch

diff --git a/savevm.c b/savevm.c
index 4069b34..94628c6 100644
--- a/savevm.c
+++ b/savevm.c
@@ -578,17 +578,14 @@  static int qemu_peek_byte(QEMUFile *f)

 int qemu_get_byte(QEMUFile *f)
 {
-    if (f->is_write) {
-        abort();
-    }
+    int result;

-    if (f->buf_index >= f->buf_size) {
-        qemu_fill_buffer(f);
-        if (f->buf_index >= f->buf_size) {
-            return 0;
-        }
+    result = qemu_peek_byte(f);
+
+    if (f->buf_index < f->buf_size) {
+        f->buf_index++;
     }
-    return f->buf[f->buf_index++];
+    return result;
 }

 int64_t qemu_ftell(QEMUFile *f)