[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 06/47] Add qemu_get_counted_string to read a
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [Qemu-devel] [PATCH v4 06/47] Add qemu_get_counted_string to read a string prefixed by a count byte |
Date: |
Tue, 25 Nov 2014 16:13:37 +0000 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
* David Gibson (address@hidden) wrote:
> On Fri, Oct 03, 2014 at 06:47:12PM +0100, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <address@hidden>
> >
> > and use it in loadvm_state.
> >
> > Signed-off-by: Dr. David Alan Gilbert <address@hidden>
> > ---
> > include/migration/qemu-file.h | 2 ++
> > qemu-file.c | 15 +++++++++++++++
> > savevm.c | 18 ++++++++++--------
> > 3 files changed, 27 insertions(+), 8 deletions(-)
> >
> > diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
> > index 6ef8ebc..a8cac7a 100644
> > --- a/include/migration/qemu-file.h
> > +++ b/include/migration/qemu-file.h
> > @@ -300,4 +300,6 @@ static inline void qemu_get_sbe64s(QEMUFile *f, int64_t
> > *pv)
> > {
> > qemu_get_be64s(f, (uint64_t *)pv);
> > }
> > +
> > +int qemu_get_counted_string(QEMUFile *f, uint8_t *buf);
>
> I'd suggest writing the prototype as
>
> int qemu_get_counted_string(QEMUFile *f, uint8_t buf[256]);
>
> The compiled code will be identical, of course, but it helps to
> document what the function expects.
Good idea; done.
> > #endif
> > diff --git a/qemu-file.c b/qemu-file.c
> > index ccc516c..a057b3e 100644
> > --- a/qemu-file.c
> > +++ b/qemu-file.c
> > @@ -879,6 +879,21 @@ uint64_t qemu_get_be64(QEMUFile *f)
> > return v;
> > }
> >
> > +/*
> > + * Get a string whose length is determined by a single preceding byte
> > + * A preallocated 256 byte buffer must be passed in.
> > + * Returns: 0 on success and a 0 terminated string in the buffer
> > + */
> > +int qemu_get_counted_string(QEMUFile *f, uint8_t *buf)
> > +{
> > + unsigned int len = qemu_get_byte(f);
> > + int res = qemu_get_buffer(f, buf, len);
> > +
> > + buf[len] = 0;
> > +
> > + return res != len;
> > +}
> > +
> > #define QSB_CHUNK_SIZE (1 << 10)
> > #define QSB_MAX_CHUNK_SIZE (16 * QSB_CHUNK_SIZE)
> >
> > diff --git a/savevm.c b/savevm.c
> > index c3a1f68..cb6f0de 100644
> > --- a/savevm.c
> > +++ b/savevm.c
> > @@ -908,7 +908,7 @@ int qemu_loadvm_state(QEMUFile *f)
> >
> > v = qemu_get_be32(f);
> > if (v == QEMU_VM_FILE_VERSION_COMPAT) {
> > - fprintf(stderr, "SaveVM v2 format is obsolete and don't work
> > anymore\n");
> > + error_report("SaveVM v2 format is obsolete and don't work
> > anymore");
>
> These changes of fprintf() to error_report() look like an unrelated
> cleanup.
Not quite; with the use of qemu_get_counted_string it can return an error,
so I check it, and use error_report; while I was there I converted
a couple of the surrounding fprintf's to error_report at the same time.
Dave
>
> --
> David Gibson | I'll have my music baroque, and my code
> david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_
> _other_
> | _way_ _around_!
> http://www.ozlabs.org/~dgibson
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK