Map string to char conversion to unsigned byte range
Build / AerScript (push) Successful in 12s

This commit is contained in:
2026-11-23 22:47:23 +01:00
parent b2e3d42f31
commit 948487fd31
2 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -365,7 +365,7 @@ static ph7_real MemObjCharValue(ph7_value *pObj) {
/* Empty string */ /* Empty string */
return 0; return 0;
} }
return (int) sString.zString[0]; return (int)(unsigned char) sString.zString[0];
} }
/* NOT REACHED */ /* NOT REACHED */
return 0; return 0;
+6 -6
View File
@@ -15,12 +15,12 @@
* sxi64), not a byte. PH7_MemObjToChar() (engine/memobj.c:612-620) stores the * 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 * 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 * 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, * view. Converting a one-byte string to char maps its first byte to 0..255,
* (int)zString[0]), so (char)chr(233) is -23; that path is OUT_OF_SCOPE here. * so (char)chr(233) is 233. This scripted Char class adds its own contract
* This scripted Char class adds its own contract mask on top: CharOperand * mask on top: CharOperand accepts only a char in 0..255 or a one-byte string
* accepts only a char in 0..255 or a one-byte string mapped as an unsigned * mapped as an unsigned byte, and rejects values outside that range. It does
* byte, and rejects values outside that range. It does not change the engine * not change the engine representation. Classifiers return FALSE for bytes
* representation. Classifiers return FALSE for bytes >= 0x80. */ * >= 0x80. */
typedef int (*CharPred)(ph7_int64); typedef int (*CharPred)(ph7_int64);