Browse Source

* fix for (w)chararray to ansi/widestring conversions after
ansi/widestring function handling change in r9718 (patch by
Sergei Gorelkin)

git-svn-id: trunk@10073 -

Jonas Maebe 17 years ago
parent
commit
76b7bfedd8
4 changed files with 77 additions and 12 deletions
  1. 1 0
      .gitattributes
  2. 14 10
      rtl/inc/astrings.inc
  3. 6 2
      rtl/inc/wustrings.inc
  4. 56 0
      tests/test/tstring9.pp

+ 1 - 0
.gitattributes

@@ -7367,6 +7367,7 @@ tests/test/tstring5.pp svneol=native#text/plain
 tests/test/tstring6.pp svneol=native#text/plain
 tests/test/tstring6.pp svneol=native#text/plain
 tests/test/tstring7.pp svneol=native#text/plain
 tests/test/tstring7.pp svneol=native#text/plain
 tests/test/tstring8.pp svneol=native#text/plain
 tests/test/tstring8.pp svneol=native#text/plain
+tests/test/tstring9.pp svneol=native#text/plain
 tests/test/tstrreal1.pp svneol=native#text/plain
 tests/test/tstrreal1.pp svneol=native#text/plain
 tests/test/tstrreal2.pp svneol=native#text/plain
 tests/test/tstrreal2.pp svneol=native#text/plain
 tests/test/tstrreal3.pp -text
 tests/test/tstrreal3.pp -text

+ 14 - 10
rtl/inc/astrings.inc

@@ -409,11 +409,12 @@ Var
   L : SizeInt;
   L : SizeInt;
 begin
 begin
   if (not assigned(p)) or (p[0]=#0) Then
   if (not assigned(p)) or (p[0]=#0) Then
-    { result is automatically set to '' }
-    exit;
-  l:=IndexChar(p^,-1,#0);
+    L := 0
+  else
+    l:=IndexChar(p^,-1,#0);
   SetLength(fpc_PChar_To_AnsiStr,L);
   SetLength(fpc_PChar_To_AnsiStr,L);
-  Move (P[0],Pointer(fpc_PChar_To_AnsiStr)^,L)
+  if L > 0 then
+    Move (P[0],Pointer(fpc_PChar_To_AnsiStr)^,L)
 end;
 end;
 
 
 
 
@@ -425,16 +426,19 @@ begin
   if (zerobased) then
   if (zerobased) then
     begin
     begin
       if (arr[0]=#0) Then
       if (arr[0]=#0) Then
-        { result is automatically set to '' }
-        exit;
-      i:=IndexChar(arr,high(arr)+1,#0);
-      if i = -1 then
-        i := high(arr)+1;
+        i := 0
+      else
+      begin  
+        i:=IndexChar(arr,high(arr)+1,#0);
+        if i = -1 then
+          i := high(arr)+1;
+      end;    
     end
     end
   else
   else
     i := high(arr)+1;
     i := high(arr)+1;
   SetLength(fpc_CharArray_To_AnsiStr,i);
   SetLength(fpc_CharArray_To_AnsiStr,i);
-  Move (arr[0],Pointer(fpc_CharArray_To_AnsiStr)^,i);
+  if i > 0 then
+    Move (arr[0],Pointer(fpc_CharArray_To_AnsiStr)^,i);
 end;
 end;
 
 
 {$ifndef FPC_STRTOCHARARRAYPROC}
 {$ifndef FPC_STRTOCHARARRAYPROC}

+ 6 - 2
rtl/inc/wustrings.inc

@@ -719,8 +719,10 @@ Var
   L : SizeInt;
   L : SizeInt;
 begin
 begin
   if (not assigned(p)) or (p[0]=#0) Then
   if (not assigned(p)) or (p[0]=#0) Then
-    { result is automatically set to '' }
+  begin
+    fpc_pchar_to_widestr := '';
     exit;
     exit;
+  end;  
   l:=IndexChar(p^,-1,#0);
   l:=IndexChar(p^,-1,#0);
   widestringmanager.Ansi2WideMoveProc(P,fpc_PChar_To_WideStr,l);
   widestringmanager.Ansi2WideMoveProc(P,fpc_PChar_To_WideStr,l);
 end;
 end;
@@ -733,8 +735,10 @@ begin
   if (zerobased) then
   if (zerobased) then
     begin
     begin
       if (arr[0]=#0) Then
       if (arr[0]=#0) Then
-        { result is automatically set to '' }
+      begin
+        fpc_chararray_to_widestr := '';
         exit;
         exit;
+      end;  
       i:=IndexChar(arr,high(arr)+1,#0);
       i:=IndexChar(arr,high(arr)+1,#0);
       if i = -1 then
       if i = -1 then
         i := high(arr)+1;
         i := high(arr)+1;

+ 56 - 0
tests/test/tstring9.pp

@@ -0,0 +1,56 @@
+program tst2;
+{$ifdef fpc}{$mode objfpc}{$h+}{$endif}
+
+var
+ a: array[0..0] of char = (#0);
+
+function test_pchar: boolean;
+var
+ s: string;
+ p: pchar;
+begin
+ p := '';
+ s := '1234567890';
+ s := p;
+ test_pchar := (s = '');
+ if not test_pchar then writeln('test_pchar failed');
+end;
+
+function test_chararray: boolean;
+var
+ s: string;
+begin
+ s := '1234567890';
+ s := a;
+ test_chararray := (s = '');
+ if not test_chararray then writeln('test_chararray failed');  
+end;
+
+function test_pchar_to_widestr: boolean;
+var
+ s: widestring;
+ p: PChar;
+begin
+ p := '';
+ s := '1234567890';
+ s := p;                         { win32: function result assign not optimized! }
+ test_pchar_to_widestr := (s = '');
+ if not test_pchar_to_widestr then writeln('test_pchar_to_widestr failed');  
+end;
+
+function test_chararray_to_widestr: boolean;
+var
+ s: widestring;
+begin
+ s := '1234567890';
+ s := a;
+ test_chararray_to_widestr := (s = '');
+ if not test_chararray_to_widestr then writeln('test_chararray_to_widestr failed');  
+end;
+
+begin
+ if not test_pchar then Halt(1);
+ if not test_chararray then Halt(2);
+ if not test_pchar_to_widestr then Halt(3);
+ if not test_chararray_to_widestr then Halt(4);
+end.