libs: libfdt: Fix Fdt::header() using bad pointer am: 68980bee75

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Virtualization/+/23107375

Change-Id: I66ed668ca124c73e21fb728314d37f0ba743f5aa
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libs/libfdt/src/lib.rs b/libs/libfdt/src/lib.rs
index 61b69f5..9785941 100644
--- a/libs/libfdt/src/lib.rs
+++ b/libs/libfdt/src/lib.rs
@@ -780,11 +780,11 @@
 
     /// Return a shared pointer to the device tree.
     pub fn as_ptr(&self) -> *const c_void {
-        self as *const _ as *const c_void
+        self.buffer.as_ptr().cast::<_>()
     }
 
     fn as_mut_ptr(&mut self) -> *mut c_void {
-        self as *mut _ as *mut c_void
+        self.buffer.as_mut_ptr().cast::<_>()
     }
 
     fn capacity(&self) -> usize {
@@ -792,8 +792,9 @@
     }
 
     fn header(&self) -> &libfdt_bindgen::fdt_header {
+        let p = self.as_ptr().cast::<_>();
         // SAFETY - A valid FDT (verified by constructor) must contain a valid fdt_header.
-        unsafe { &*(&self as *const _ as *const libfdt_bindgen::fdt_header) }
+        unsafe { &*p }
     }
 
     fn totalsize(&self) -> usize {