mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 22:06:40 +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/tstrtobool.pp svneol=native#text/plain
|
||||||
tests/test/units/sysutils/tunifile.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/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/sysutils/twstrcmp.pp svneol=native#text/plain
|
||||||
tests/test/units/ucomplex/tcsqr1.pp svneol=native#text/pascal
|
tests/test/units/ucomplex/tcsqr1.pp svneol=native#text/pascal
|
||||||
tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
|
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;
|
function WideStrAlloc(Size: cardinal): PWideChar;
|
||||||
begin
|
begin
|
||||||
getmem(result,size*2+sizeof(cardinal));
|
getmem(result,size*2+sizeof(cardinal));
|
||||||
cardinal(pointer(result)^):=size*2+sizeof(cardinal);
|
PCardinal(result)^:=size*2+sizeof(cardinal);
|
||||||
inc(result,sizeof(cardinal));
|
result:=PWideChar(PByte(result)+sizeof(cardinal));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function StrBufSize(str: pwidechar): cardinal;
|
function StrBufSize(str: pwidechar): cardinal;
|
||||||
begin
|
begin
|
||||||
if assigned(str) then
|
if assigned(str) then
|
||||||
result:=cardinal(pointer(str-sizeof(cardinal))^)-sizeof(cardinal)
|
result:=(PCardinal(PByte(str)-sizeof(cardinal))^)-sizeof(cardinal)
|
||||||
else
|
else
|
||||||
result := 0;
|
result := 0;
|
||||||
end;
|
end;
|
||||||
@ -484,8 +484,8 @@ procedure StrDispose(str: pwidechar);
|
|||||||
begin
|
begin
|
||||||
if assigned(str) then
|
if assigned(str) then
|
||||||
begin
|
begin
|
||||||
dec(str,sizeof(cardinal));
|
str:=PWideChar(PByte(str)-sizeof(cardinal));
|
||||||
freemem(str,cardinal(pointer(str)^));
|
freemem(str,PCardinal(str)^);
|
||||||
end;
|
end;
|
||||||
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