This is used by Java bindings to compare all pointers against those
returned by its malloc wrap, possibly catching some simple
use-after-free or invalid pointer deref bugs.
It is exposed only when built as debug and defined in C headers
with `LDK_DEBUG_BUILD` defined.
[ptr]
non_null_attribute = "NONNULL_PTR"
+
+[defines]
+"test_mod_pointers" = "LDK_DEBUG_BUILD"
use bitcoin::bech32;
use std::convert::TryInto; // Bindings need at least rustc 1.34
-
+use core::ffi::c_void;
use std::io::{Cursor, Read}; // TODO: We should use core2 here when we support no_std
#[repr(C)]
}
}
+#[cfg(test_mod_pointers)]
+#[no_mangle]
+/// This function exists for memory safety testing purposes. It should never be used in production
+/// code
+pub extern "C" fn __unmangle_inner_ptr(ptr: *const c_void) -> *const c_void {
+ if ptr as usize == 1 {
+ core::ptr::null()
+ } else {
+ unsafe { ptr.cast::<u8>().sub(4096).cast::<c_void>() }
+ }
+}
+
pub(crate) struct SmartPtr<T> {
ptr: *mut T,
}