mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-19 23:39:31 +02:00
* fixed pointer arithmetic errors in WideStrAlloc/StrBufSize/StrDispose
(patch by Iks, mantis #29710) git-svn-id: trunk@33271 -
This commit is contained in:
parent
697aed738c
commit
2b210335a1
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -13220,6 +13220,7 @@ tests/test/units/sysutils/tstrcmp.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/tstrtobool.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/tunifile.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/tuplow.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/twstralloc.pp svneol=native#text/plain
|
||||
tests/test/units/sysutils/twstrcmp.pp svneol=native#text/plain
|
||||
tests/test/units/ucomplex/tcsqr1.pp svneol=native#text/pascal
|
||||
tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
|
||||
|
@ -468,14 +468,14 @@ function strnew(p : pwidechar) : pwidechar; overload;
|
||||
function WideStrAlloc(Size: cardinal): PWideChar;
|
||||
begin
|
||||
getmem(result,size*2+sizeof(cardinal));
|
||||
cardinal(pointer(result)^):=size*2+sizeof(cardinal);
|
||||
inc(result,sizeof(cardinal));
|
||||
PCardinal(result)^:=size*2+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;
|
||||
@ -484,8 +484,8 @@ procedure StrDispose(str: pwidechar);
|
||||
begin
|
||||
if assigned(str) then
|
||||
begin
|
||||
dec(str,sizeof(cardinal));
|
||||
freemem(str,cardinal(pointer(str)^));
|
||||
str:=PWideChar(PByte(str)-sizeof(cardinal));
|
||||
freemem(str,PCardinal(str)^);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
14
tests/test/units/sysutils/twstralloc.pp
Normal file
14
tests/test/units/sysutils/twstralloc.pp
Normal file
@ -0,0 +1,14 @@
|
||||
{ %opt=-g-h }
|
||||
|
||||
uses
|
||||
sysutils;
|
||||
|
||||
var
|
||||
pw: pwidechar;
|
||||
begin
|
||||
pw:=widestralloc(1);
|
||||
pw^:='a';
|
||||
if StrBufSize(pw)<>2 then
|
||||
halt(1);
|
||||
StrDispose(pw);
|
||||
end.
|
Loading…
Reference in New Issue
Block a user