#1 2019-12-04 11:19:31

Amir
Member
From: UAE
Registered: 2010-08-17
Posts: 36

Length of unicode string by pointer in new PosExStringPas...

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

#2 2019-12-05 10:33:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Length of unicode string by pointer in new PosExStringPas...

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. smile

Offline

Board footer

Powered by FluxBB