From 948487fd3138ae4ddb482467b16c54440ff5017d Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Mon, 23 Nov 2026 22:47:23 +0100 Subject: [PATCH] Map string to char conversion to unsigned byte range --- engine/memobj.c | 2 +- modules/char/char.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/memobj.c b/engine/memobj.c index b8d3ac8..aa4b120 100644 --- a/engine/memobj.c +++ b/engine/memobj.c @@ -365,7 +365,7 @@ static ph7_real MemObjCharValue(ph7_value *pObj) { /* Empty string */ return 0; } - return (int) sString.zString[0]; + return (int)(unsigned char) sString.zString[0]; } /* NOT REACHED */ return 0; diff --git a/modules/char/char.c b/modules/char/char.c index 3e22d24..c747fc6 100644 --- a/modules/char/char.c +++ b/modules/char/char.c @@ -15,12 +15,12 @@ * sxi64), not a byte. PH7_MemObjToChar() (engine/memobj.c:612-620) stores the * integer unchanged: (char)128/233/255 give 128/233/255, but (char)256 gives * 256 and (char)-1 gives -1 (no clamp); ph7_value_to_int() shows only a 32-bit - * view. The engine's string-to-char path is signed (engine/memobj.c:368, - * (int)zString[0]), so (char)chr(233) is -23; that path is OUT_OF_SCOPE here. - * This scripted Char class adds its own contract mask on top: CharOperand - * accepts only a char in 0..255 or a one-byte string mapped as an unsigned - * byte, and rejects values outside that range. It does not change the engine - * representation. Classifiers return FALSE for bytes >= 0x80. */ + * view. Converting a one-byte string to char maps its first byte to 0..255, + * so (char)chr(233) is 233. This scripted Char class adds its own contract + * mask on top: CharOperand accepts only a char in 0..255 or a one-byte string + * mapped as an unsigned byte, and rejects values outside that range. It does + * not change the engine representation. Classifiers return FALSE for bytes + * >= 0x80. */ typedef int (*CharPred)(ph7_int64);