View Issue Details

IDProjectCategoryView StatusLast Update
0031103LazarusLazUtilspublic2016-12-12 21:56
ReporterBart BroersmaAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWindowsOS VersionWin7
Product VersionProduct Build 
Target Version1.6.4Fixed in Version1.6.4 
Summary0031103: UnicodeToUtf8(0) returns empty string, where it should return Chr(0)
DescriptionThe 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 Reproduceprocedure 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 Informationfunction 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;
TagsNo tags attached.
Fixed in Revisionr53659
LazTarget1.6.4
Widgetset
Attached Files

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2016-12-11 14:10 Bart Broersma New Issue
2016-12-12 21:56 Bart Broersma Fixed in Revision => r53659
2016-12-12 21:56 Bart Broersma LazTarget - => 1.6.4
2016-12-12 21:56 Bart Broersma Status new => resolved
2016-12-12 21:56 Bart Broersma Fixed in Version => 1.6.4
2016-12-12 21:56 Bart Broersma Resolution open => fixed
2016-12-12 21:56 Bart Broersma Assigned To => Bart Broersma
2016-12-12 21:56 Bart Broersma Target Version => 1.6.4
2016-12-12 21:56 Bart Broersma Status resolved => closed