From f0e92c743477c8bfe25326e5eeb8dab2850fbcfc Mon Sep 17 00:00:00 2001 From: Inna Khachikyan Date: Thu, 17 Apr 2025 23:44:56 +0400 Subject: [PATCH] modified Index checking to handle run-time variable index containing negative value --- src/runtime/SYSTEM.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/runtime/SYSTEM.h b/src/runtime/SYSTEM.h index 2ecdc7f9..39d594ed 100644 --- a/src/runtime/SYSTEM.h +++ b/src/runtime/SYSTEM.h @@ -116,9 +116,11 @@ extern void Modules_AssertFail(INT32 x); // Index checking -static inline INT64 __XF(UINT64 i, UINT64 ub) {if (i >= ub) {__HALT(-2);} return i;} -#define __X(i, ub) (((i)<(ub))?i:(__HALT(-2),0)) - +static inline INT64 __XF(INT64 i, UINT64 ub) { + if (i < 0 || (UINT64)i >= ub) __HALT(-2); + return i; +} +#define __X(i, ub) (((i) >= 0 && (i) < (ub)) ? (i) : (__HALT(-2),0)) // Range checking, and checked SHORT and CHR functions