From 939c23c03bb645efc71b334293fdb714a477c861 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Thu, 7 Mar 2024 10:01:19 -0800 Subject: [PATCH] Additional check for bad stack offset calculation Pointer difference calculations on an inappropriate stack pointer could result in a negative offset, not just an offset that is too large to fit in 16 bits. Complain if either case occurs. --- inc/adr68k.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/adr68k.h b/inc/adr68k.h index 9799780..42cae9c 100644 --- a/inc/adr68k.h +++ b/inc/adr68k.h @@ -63,8 +63,8 @@ static inline DLword StackOffsetFromNative(void *SAddr) { /* Stack offsets are expressed as an offset in DLwords from the stack base */ ptrdiff_t hoffset = (DLword *)SAddr - Stackspace; - if (hoffset > 0xffff) { - printf("Stack offset is too large: 0x%tx\n", hoffset); + if (hoffset > 0xffff || hoffset < 0) { + printf("Stack offset is out of range: 0x%tx\n", hoffset); } return (DLword)hoffset; }