UnicodeToUtf8(0) returns empty string, where it should return Chr(0)
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
The function UnicodeToUTF8(CodePoint: cardinal): string; returns an empty string if CodePoint = 0.
It should however return Chr(0), after all this is Pascal, which allows null characters inside (ansi)strings.
This bug makes the TTestUnicode test suite fail.
Steps to reproduce:
procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
begin
S := UnicodeToUTF8(0);
writeln('Length(S) = ',Length(S),' [expected: 1]');
end;
It will output:
Length(S) = 0 [expected: 1]
Additional information:
function UnicodeToUTF8(CodePoint: cardinal): string;
var
Buf: array[0..6] of Char;
Len: Integer;
begin
Len:=UnicodeToUTF8Inline(CodePoint, @Buf[0]);
Buf[Len]:=#0;
Result := StrPas(@Buf[0]); << this is the culprit
end;
Mantis conversion info:
- Mantis ID: 31103
- OS: Windows
- OS Build: Win7
- Platform: i386
- Fixed in version: 1.6.4
- Fixed in revision: r53659 (#545d1bb6)
- Target version: 1.6.4