[RFC PATCH v1 10/17] vmstate: Remove curr_elem_p

Fabiano Rosas posted 17 patches 1 week, 2 days ago
[RFC PATCH v1 10/17] vmstate: Remove curr_elem_p
Posted by Fabiano Rosas 1 week, 2 days ago
The usage of curr_elem_p for holding the array of pointers element is
a bit confusing. The side effect of updating what this variable points
to is not very clear. Remove it in favor of a local array_elem
variable with the same purpose, but make it of type void** instead,
since this is what it really is. Move it under the
VMS_ARRAY_OF_POINTER check.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 migration/vmstate.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/migration/vmstate.c b/migration/vmstate.c
index 0cdfde2232..85e63305f6 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -261,16 +261,15 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,
                 /* If we will process the load of field? */
                 bool load_field = true;
                 bool ok = true;
-                void *curr_elem_p = first_elem + size * i;
-                void *curr_elem = curr_elem_p;
+                void *curr_elem;
 
                 if (field->flags & VMS_ARRAY_OF_POINTER) {
+                    void **array_elem = (void **)first_elem + i;
                     bool use_dynamic_array =
                         field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC;
                     bool use_marker_field;
 
-                    curr_elem = *(void **)curr_elem_p;
-
+                    curr_elem = *array_elem;
                     use_marker_field = use_dynamic_array || !curr_elem;
 
                     if (use_marker_field) {
@@ -293,9 +292,11 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,
                              */
                             curr_elem = g_malloc0(field->size);
                             /* Remember to update the root pointer! */
-                            *(void **)curr_elem_p = curr_elem;
+                            *(void **)array_elem = curr_elem;
                         }
                     }
+                } else {
+                    curr_elem = first_elem + size * i;
                 }
 
                 if (load_field) {
-- 
2.51.0