vmstate: Stop checking size for nullptr compression
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. Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Juraj Marcin <jmarcin@redhat.com> Link: https://lore.kernel.org/qemu-devel/20260401202844.673494-11-peterx@redhat.com Signed-off-by: Fabiano Rosas <farosas@suse.de>
Fabiano Rosas committed
Apr 1, 2026 at 16:28 UTC
1c8784c9fdf61074030e9889c33a959ecbec5fe9
1 file changed
+3
-3
migration/vmstate.c
+3
-3
@@ -682,14 +682,14 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
682
const VMStateField *inner_field;
683
/* maximum number of elements to compress in the JSON blob */
684
int max_elems = vmsd_can_compress(field) ? (n_elems - i) : 1;
685
- bool use_marker_field, is_null;
685
+ bool use_marker_field, is_null = false;
686
687
if (field->flags & VMS_ARRAY_OF_POINTER) {
688
assert(curr_elem);
689
curr_elem = *(void **)curr_elem;
690
+ is_null = !curr_elem;
691
}
692
692
- is_null = !curr_elem && size;
693
use_marker_field = use_dynamic_array || is_null;
694
695
if (use_marker_field) {
@@ -717,7 +717,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
717
718
for (int j = i + 1; j < n_elems; j++) {
719
void *elem = *(void **)(first_elem + size * j);
720
- bool elem_is_null = !elem && size;
720
+ bool elem_is_null = !elem;
721
722
if (is_null != elem_is_null) {
723
max_elems = j - i;