Browse Source

* convert constant widestring to ansistring before assigning to pchar

git-svn-id: trunk@1482 -
peter 20 years ago
parent
commit
8d9e9b24a6
3 changed files with 22 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 5 1
      compiler/ncnv.pas
  3. 16 0
      tests/webtbs/tw4254.pp

+ 1 - 0
.gitattributes

@@ -6314,6 +6314,7 @@ tests/webtbs/tw4239.pp svneol=native#text/plain
 tests/webtbs/tw4240.pp svneol=native#text/plain
 tests/webtbs/tw4247.pp svneol=native#text/plain
 tests/webtbs/tw4253.pp svneol=native#text/plain
+tests/webtbs/tw4254.pp svneol=native#text/plain
 tests/webtbs/tw4260.pp svneol=native#text/plain
 tests/webtbs/tw4266.pp -text
 tests/webtbs/tw4272.pp svneol=native#text/plain

+ 5 - 1
compiler/ncnv.pas

@@ -1031,7 +1031,11 @@ implementation
       begin
          result:=nil;
          if is_pwidechar(resulttype.def) then
-           inserttypeconv(left,cwidestringtype);
+           inserttypeconv(left,cwidestringtype)
+         else
+           if is_pchar(resulttype.def) and
+              is_widestring(left.resulttype.def) then
+             inserttypeconv(left,cansistringtype);
       end;
 
 

+ 16 - 0
tests/webtbs/tw4254.pp

@@ -0,0 +1,16 @@
+{ Source provided for Free Pascal Bug Report 4254 }
+{ Submitted by "rimga" on  2005-08-04 }
+{ e-mail: [email protected] }
+//when source encoded in utf8
+var
+  p: pchar;
+begin
+  p:= 'abc'#261;
+  //constant is internally treated as of wide chars a0b0c0#105 (it is ok)
+  //but assigning it to pchar it has to be converted to 8-bit chars
+  if strlen(p)= 1 then
+    begin
+    writeln('problem');
+    halt(1);
+    end;
+end.