[fpc-devel] Bug in PWidechar and refcounting
Joost van der Sluis
joost at cnoc.nl
Sun Feb 13 01:31:47 CET 2005
Hi all,
the bug-report on the website doesn't work, so I write a mail:
If you assign a widechar to a pwidechar, the refcount isn't
increased. This construct is often used in the variants-code, which is
allowed, according to the comments at the top of wstrings.inc.
An example:
Program test;
var PW : PWideChar;
dummy : AnsiString;
procedure Set_PW;
var
W : WideString;
s : ansistring;
begin
s := 'Hello world'; // Can't assign directly to W, because that's
W := s; // interpreted as a constant with a refcount of -1
PW := PWideChar(W); // <- Bug, refcount of W (and PW) isn't increased
end; // <- Memory at @W is deallocated, since refcount=0
begin
Set_PW;
SetLength(Dummy,3); // The dummy is allocated at the same address as PW
writeln(pchar(PW)[0]); // Should write 'H', but it doesn't
end.
JoJo,
Joost.
More information about the fpc-devel
mailing list