From: Gerd Hoffmann <kraxel@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] add VMSTATE_BOOL
Date: Tue, 09 Nov 2010 10:37:37 +0100 [thread overview]
Message-ID: <4CD91661.6030102@redhat.com> (raw)
In-Reply-To: <20101108174752.GC8498@redhat.com>
Hi,
>> +#define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
>> + VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
>> +
>
> Why don't we pack the bits?
Point being? As long as we don't save *big* arrays of bools it simply
isn't worth the effort IMHO. And for big arrays we'll probably wouldn't
use bool in the first place ...
>> +/* bool */
>> +
>> +static int get_bool(QEMUFile *f, void *pv, size_t size)
>> +{
>> + bool *v = pv;
>> + *v = qemu_get_byte(f);
>> + return 0;
>
> We must really validate that the value is 0 or 1.
> If it's not, we will get undefined behaviour.
I disagree.
You indeed have a bug in case your bool ends up with a value being
neither 0 nor 1. That is completely independant from savevm/loadvm
though, it can trip you up even in case you don't save/load the VM at all.
>> +}
>> +
>> +static void put_bool(QEMUFile *f, void *pv, size_t size)
>> +{
>> + bool *v = pv;
>> + qemu_put_byte(f, *v);
>
> Is there a guarantee that bool is a single byte, BTW?
No. bool must be 0 or 1 though, and a single byte is big enough to keep
that information.
cheers,
Gerd
next prev parent reply other threads:[~2010-11-09 9:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-01 14:51 [Qemu-devel] [PATCH] add VMSTATE_BOOL Gerd Hoffmann
2010-11-01 15:08 ` [Qemu-devel] " malc
2010-11-08 17:47 ` Michael S. Tsirkin
2010-11-09 9:23 ` Markus Armbruster
2010-11-09 9:32 ` Paolo Bonzini
2010-11-09 9:37 ` Gerd Hoffmann [this message]
2010-11-09 11:34 ` Michael S. Tsirkin
2010-11-09 11:50 ` Gerd Hoffmann
2010-11-09 13:05 ` Michael S. Tsirkin
2010-11-09 13:28 ` Gerd Hoffmann
2010-11-09 13:37 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CD91661.6030102@redhat.com \
--to=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.