View Issue Details

IDProjectCategoryView StatusLast Update
0020668LazarusLCLpublic2011-12-03 14:25
ReporterBart BroersmaAssigned ToFelipe Monteiro de Carvalho 
PriorityhighSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWinMeOS VersionMS
Product Version0.9.31 (SVN)Product Buildr32978 
Target VersionFixed in Version0.9.31 (SVN) 
Summary0020668: Wrong implementation of Wide2AnsiMove in paswstring.pas. (Breaks Lazarus and compiled programs on Win9x systems).
DescriptionThe implementation of Wide2AnsiMove in ($LazarusDir)/components/lazutils/paswstring.pas uses the wrong count parameter in the call to System.Move().
Therefor assigning a WideString variable to an AnsiString fails.

As a result, in the IDE (on Win9x), the ImageListEditor does no longer function, that is, when you press the Add... button, the OpenPictureDialog does not show.
Somewhere along the line of showing this dialog on Win9x systems there is a call to Wide2AnsiMove with source = LAZ_PIC_DIALOG_TEMPLATE and the resulting outputted AnsiString is LAZ_PIC_DIAL (padded with null-characters or garbage).
Steps To ReproduceIn a Lazarus project include the paswstring unit.

procedure TForm1.TestAllBtnClick(Sender: TObject);
var
  W1, W2, W3: WideString;
  S1, S2, S3: String;
begin
  W1 := 'abc';
  W2 := 'ABC';
  W3 := WideUppercase(W1);
  if W3 <> W2 then writeln('####### Fail on WideUpperCase')
    else writeln('WideUppercase OK');
  W1 := 'abc';
  W2 := 'ABC';
  W3 := WideLowerCase(W2);
  if W1 <> W3 then writeln('####### Fail on WideLowerCase')
    else writeln('WideLowercase OK');
  S1 := 'abc';
  S2 := 'ABC';
  S3 := Utf8UpperCase(S1);
  if S3 <> S2 then writeln('####### Fail on Utf8UpperCase')
    else writeln('Utf8Uppercase OK');
  S1 := 'abc';
  S2 := 'ABC';
  S3 := Utf8LowerCase(S1);
  if S1 <> S3 then writeln('####### Fail on Utf8LowerCase')
    else writeln('Utf8Lowercase OK');
  W1 := 'ABC';
  S1 := W1;
  if (S1 <> W1) then writeln('###### Fail on Wide2Ansi')
    else writeln('Wide2Ansi OK');
  S1 := 'ABC';
  W1 := S1;
  if (S1 <> W1) then writeln('###### Fail on Ansi2Wide')
    else writeln('Ansi2Wide OK');
end;

Build and run on Windows 98 or WindowsME

Expected output:

WideUppercase OK
WideLowercase OK
Utf8Uppercase OK
Utf8Lowercase OK
Wide2Ansi OK
Ansi2Wide OK

Actual output:

WideUppercase OK
WideLowercase OK
Utf8Uppercase OK
Utf8Lowercase OK
###### Fail on Wide2Ansi
Ansi2Wide OK
Additional Informationprocedure Wide2AnsiMove(source:pwidechar;var dest:ansistring;len:SizeInt);
var
  widestr: widestring;
begin
  {$ifdef PASWSTRING_VERBOSE}WriteLn('Wide2AnsiMove START');{$endif}
  // Copy the originating string taking into account the specified length
  SetLength(widestr, len);
  System.Move(source^, widestr[1], len);

This should be replaced by
  System.Move(source^, widestr[1], len * SizeOf(WChar));

Patch is attached.

NB. Target = 0.99.0 because this is a regression.
TagsNo tags attached.
Fixed in Revision33538, 33553
LazTarget-
Widgetset
Attached Files
  • paswstring.wide2ansimove.diff (595 bytes)
    Index: components/lazutils/paswstring.pas
    ===================================================================
    --- components/lazutils/paswstring.pas	(revision 32978)
    +++ components/lazutils/paswstring.pas	(working copy)
    @@ -35,7 +35,7 @@
       {$ifdef PASWSTRING_VERBOSE}WriteLn('Wide2AnsiMove START');{$endif}
       // Copy the originating string taking into account the specified length
       SetLength(widestr, len);
    -  System.Move(source^, widestr[1], len);
    +  System.Move(source^, widestr[1], len * SizeOf(WChar));
     
       // Now convert it, using UTF-16 -> UTF-8
       dest := UTF16ToUTF8(widestr);
    

Relationships

has duplicate 0020672 closedFelipe Monteiro de Carvalho IDE not start if Windows user name non ascii 

Activities

2011-11-11 21:09

 

paswstring.wide2ansimove.diff (595 bytes)
Index: components/lazutils/paswstring.pas
===================================================================
--- components/lazutils/paswstring.pas	(revision 32978)
+++ components/lazutils/paswstring.pas	(working copy)
@@ -35,7 +35,7 @@
   {$ifdef PASWSTRING_VERBOSE}WriteLn('Wide2AnsiMove START');{$endif}
   // Copy the originating string taking into account the specified length
   SetLength(widestr, len);
-  System.Move(source^, widestr[1], len);
+  System.Move(source^, widestr[1], len * SizeOf(WChar));
 
   // Now convert it, using UTF-16 -> UTF-8
   dest := UTF16ToUTF8(widestr);

Zeljan Rikalo

2011-11-12 08:03

developer   ~0054026

@Felipe, please review that patch

Bart Broersma

2011-11-15 09:57

developer   ~0054090

Reminder sent to: Felipe Monteiro de Carvalho

Felipe: please forgive me for being impatient, but can you please apply the patch?
I cannot work on my project anymore because of this bug.

Felipe Monteiro de Carvalho

2011-11-15 10:10

developer   ~0054091

Where is paswstring used in the IDE? I don't see this.

Felipe Monteiro de Carvalho

2011-11-15 10:16

developer   ~0054092

I commited the fix in rev 33538 but I am still puzzled about how the IDE could be using paswstring at all.

Zeljan Rikalo

2011-11-15 10:59

developer   ~0054094

@Felipe, I guess that he's using paswstring in his local svn copy.

Anton

2011-11-15 18:19

reporter   ~0054099

lazutils unit uses paswstring. It's enough to install WideStringManager from paswstring unit.

Bart Broersma

2011-11-15 18:32

developer   ~0054100

Yes it is used by Lazutils.

I didn't even know of the existence of this unit, until disecting across 1024 revisions eventually pointed to this file.

The puzzling fact for me was that when I wrote a demo program invoking the ImageListEditor (this is how I initially stumbled upon this issue in the IDE) everything worked just fine.
Then after finding out that paswstring.pas was probably to blame (it breaks at r32967, and up to r32975 Lazarus just dies on startup) I then added paswstring to the uses clause of my demo, and sure the the bug appeared also.

Felipe Monteiro de Carvalho

2011-11-16 06:58

developer   ~0054110

I found where the IDE was using paswstrings and removed this link.

Please test and close if ok.

Issue History

Date Modified Username Field Change
2011-11-11 21:09 Bart Broersma New Issue
2011-11-11 21:09 Bart Broersma File Added: paswstring.wide2ansimove.diff
2011-11-11 21:09 Bart Broersma LazTarget => -
2011-11-12 08:03 Zeljan Rikalo Note Added: 0054026
2011-11-12 08:03 Zeljan Rikalo Assigned To => Felipe Monteiro de Carvalho
2011-11-12 08:03 Zeljan Rikalo Status new => assigned
2011-11-15 09:57 Bart Broersma Note Added: 0054090
2011-11-15 10:10 Felipe Monteiro de Carvalho Note Added: 0054091
2011-11-15 10:16 Felipe Monteiro de Carvalho Fixed in Revision => 33538
2011-11-15 10:16 Felipe Monteiro de Carvalho Note Added: 0054092
2011-11-15 10:59 Zeljan Rikalo Note Added: 0054094
2011-11-15 16:35 Felipe Monteiro de Carvalho Status assigned => feedback
2011-11-15 18:19 Anton Note Added: 0054099
2011-11-15 18:32 Bart Broersma Note Added: 0054100
2011-11-16 06:58 Felipe Monteiro de Carvalho Fixed in Revision 33538 => 33538, 33553
2011-11-16 06:58 Felipe Monteiro de Carvalho Status feedback => resolved
2011-11-16 06:58 Felipe Monteiro de Carvalho Fixed in Version => 0.9.31 (SVN)
2011-11-16 06:58 Felipe Monteiro de Carvalho Resolution open => fixed
2011-11-16 06:58 Felipe Monteiro de Carvalho Note Added: 0054110
2011-11-18 16:40 Juha Manninen Relationship added related to 0020672
2011-11-18 16:49 Felipe Monteiro de Carvalho Relationship replaced has duplicate 0020672
2011-12-03 14:25 Bart Broersma Status resolved => closed