Possible Problems in Wide String Handling?
Original Reporter info from Mantis: lks
-
Reporter name:
Original Reporter info from Mantis: lks
- Reporter name:
Description:
In rtl/objpas/sysutils/sysuni.inc, the code in
WideStrAlloc
StrBufSize
StrDispose
adds or subtracts a sizeof(cardinal) to a PWideChar when computing the offset for the size field in a PWideString. In other words, the location of the size field is -8 from the start of the WideChar data. However, some of the other routines only allocate 2 * Length(# of WideChar data + 4).
I am guessing what is meant is (code untested)
function WideStrAlloc(Size: cardinal): PWideChar;
begin
getmem(result,size*2+sizeof(cardinal));
cardinal(pointer(result)^):=size*2+sizeof(cardinal);
//inc(result,sizeof(cardinal));
result:=PWideChar(PByte(result)+sizeof(cardinal));
end;
function StrBufSize(str: pwidechar): cardinal;
begin
if assigned(str) then
//result:=cardinal(pointer(str-sizeof(cardinal))^)-sizeof(cardinal)
result:=(PCardinal(PByte(str)-sizeof(cardinal))^)-sizeof(cardinal)
else
result := 0;
end;
procedure StrDispose(str: pwidechar);
begin
if assigned(str) then
begin
//dec(str,sizeof(cardinal));
str:=PWideChar(PByte(str)-sizeof(cardinal));
freemem(str,cardinal(pointer(str)^));
end;
end;
Am I missing something obvious? If not I can make a patch.
Mantis conversion info:
- Mantis ID: 29710
- OS: Windows 10
- Build: 33111
- Platform: x86_64-win64
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 33271 (#2b210335)