|
From: | Gerd Hoffmann |
Subject: | [Qemu-devel] Re: [PATCH] add VMSTATE_BOOL |
Date: | Tue, 09 Nov 2010 10:37:37 +0100 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100827 Red Hat/3.1.3-1.el6 Thunderbird/3.1.3 |
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
[Prev in Thread] | Current Thread | [Next in Thread] |