diff options
| author | Kenix3 <kenixwhisperwind@gmail.com> | 2020-06-04 21:41:44 -0400 |
|---|---|---|
| committer | Kenix3 <kenixwhisperwind@gmail.com> | 2020-06-04 21:41:44 -0400 |
| commit | 664182c2899ba341be31f4cd7364a74867ee422c (patch) | |
| tree | 3e6b6414cbfadb915acf867e6c88380045b01a04 /src/code/z_lib.c | |
| parent | dfbcac539ead5f73fb8e3e8954dded9ccd18f3fe (diff) | |
Fixes known undefined behaviour from DmaMgr and Lib_Ptr taking u32 rather than void*
Diffstat (limited to 'src/code/z_lib.c')
| -rw-r--r-- | src/code/z_lib.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/code/z_lib.c b/src/code/z_lib.c index b30941ae5..f4209e98b 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -606,30 +606,37 @@ f32 Lib_PushAwayVec3f(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) { void Lib_Nop801004FC(void) {} -u32 Lib_PtrSegToVirt(void* ptr) { - return(gRspSegmentPhysAddrs[((u32)ptr << 4) >> 28] + ((u32)ptr & 0xFFFFFF)) + 0x80000000; +void* Lib_PtrSegToVirt(void* ptr) { + // TODO: PHYSICAL_TO_VIRTUAL macro + // UB to cast the pointer to u32 + return (void*)(((u32)gRspSegmentPhysAddrs[((u32)ptr << 4) >> 28] + ((u32)ptr & 0xFFFFFF)) + 0x80000000); } -u32 Lib_PtrSegToVirtNull(void* ptr) { +void* Lib_PtrSegToVirtNull(void* ptr) { + // UB to cast the pointer to u32 in order to bitshift. if (((u32)ptr >> 28) == 0) { - return (u32)ptr; + return ptr; } - return(gRspSegmentPhysAddrs[((u32)ptr << 4) >> 28] + ((u32)ptr & 0xFFFFFF)) + 0x80000000; + // TODO: PHYSICAL_TO_VIRTUAL macro + // UB to cast the pointer to u32 + return (void*)(((u32)gRspSegmentPhysAddrs[((u32)ptr << 4) >> 28] + ((u32)ptr & 0xFFFFFF)) + 0x80000000); } -u32 Lib_PtrSegToK0(void* ptr) { +void* Lib_PtrSegToK0(void* ptr) { if (ptr == NULL) { - return 0; + return NULL; } else { - return (u32)ptr + 0x80000000; + // TODO: PHYSICAL_TO_VIRTUAL macro + return (void*)((u32)ptr + 0x80000000); } } -u32 Lib_PtrSegToK0Null(void* ptr) { +void* Lib_PtrSegToK0Null(void* ptr) { if (ptr == NULL) { - return 0; + return NULL; } else { - return (u32)ptr + 0x80000000; + // TODO: PHYSICAL_TO_VIRTUAL macro + return (void*)((u32)ptr + 0x80000000); } }
\ No newline at end of file |
