[RFC PATCH v1 03/17] vmstate: Stop checking size for nullptr compression

Fabiano Rosas posted 17 patches 1 week, 2 days ago
[RFC PATCH v1 03/17] vmstate: Stop checking size for nullptr compression
Posted by Fabiano Rosas 1 week, 2 days ago
The NULL pointer marker code applies only to VMS_ARRAY_OF_POINTER,
where the size is never NULL. Move the setting of is_null under
VMS_ARRAY_OF_POINTER, so we can stop checking the size.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
AFAICS, the size actually should never be NULL, but there are a few
vmsds doing a hack with VMS_SINGLE. I can't be bothered to learn about
it right now.
---
 migration/vmstate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/migration/vmstate.c b/migration/vmstate.c
index 7edfa3d990..d7b1bc6b86 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -635,15 +635,15 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
             for (i = 0; i < n_elems; i++) {
                 void *curr_elem = first_elem + size * i;
                 const VMStateField *inner_field;
-                bool use_marker_field, is_null;
+                bool use_marker_field, is_null = false;
                 int max_elems = n_elems - i;
 
                 if (field->flags & VMS_ARRAY_OF_POINTER) {
                     assert(curr_elem);
                     curr_elem = *(void **)curr_elem;
+                    is_null = !curr_elem;
                 }
 
-                is_null = (!curr_elem && size);
                 use_marker_field = use_dynamic_array || is_null;
 
                 if (use_marker_field) {
@@ -672,7 +672,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
 
                     for (int j = i + 1; j < n_elems; j++) {
                         void *elem = *(void **)(first_elem + size * j);
-                        bool elem_is_null = !elem && size;
+                        bool elem_is_null = !elem;
 
                         if (is_null != elem_is_null) {
                             max_elems = j - i;
-- 
2.51.0