You are not logged in.
Hi dear Arnaud,
As PChar is compiled with {$POINTERMATH ON}, direct pointer arithmatic operations should be applied with the multiplication of the pointer's base type-size with the value specified by operation.
Thus in for eg:
function PosExStringPas(pSub, p: PChar; Offset: PtrUInt): PtrInt;
We calculate the length of the "p" and "pSub" in Delphi version as
PInteger(p - 4)^; //and so for "pSub"
This actually is computed as "PByet(p) - 8", Where Char is two-byte sized (in Unicode Versions of Delphi).
Seems it should be edited for both "p" and "pSub" as for eg:
PInteger(PByte(p) - 4)^;
For always correct access to string's length field.
Please let me know if I am wrong...
Thanks.
Last edited by Amir (2019-12-04 11:32:04)
Amir
Offline
Now, you are perfectly right: this was a bug of this new function.
It should be properly fixed by https://synopse.info/fossil/info/57e8496c5d
I also added some associated regression tests - as expected.
Offline