kvm: selftests: avoid type punning
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 20 May 2019 10:02:16 +0000 (12:02 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 24 May 2019 19:27:05 +0000 (21:27 +0200)
Avoid warnings from -Wstrict-aliasing by using memcpy.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/lib/ucall.c
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c

index a2ab38be2f479452abf84db440ae96e70963cec7..b701a01cfcb62c619860783fb387c177d352bcbd 100644 (file)
@@ -142,7 +142,7 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
                vm_vaddr_t gva;
                TEST_ASSERT(run->mmio.is_write && run->mmio.len == 8,
                            "Unexpected ucall exit mmio address access");
-               gva = *(vm_vaddr_t *)run->mmio.data;
+               memcpy(&gva, run->mmio.data, sizeof(gva));
                memcpy(uc, addr_gva2hva(vm, gva), sizeof(*uc));
        }
 
index 61a2163cf9f182ec7b5e6c4a689d8d91677d21b1..9d62e2c7e024d2ea8d60dac2d184d954b7a607c8 100644 (file)
@@ -75,7 +75,7 @@ void set_revision_id_for_vmcs12(struct kvm_nested_state *state,
                                u32 vmcs12_revision)
 {
        /* Set revision_id in vmcs12 to vmcs12_revision. */
-       *(u32 *)(state->data) = vmcs12_revision;
+       memcpy(state->data, &vmcs12_revision, sizeof(u32));
 }
 
 void set_default_state(struct kvm_nested_state *state)