瀏覽代碼

* don't call the ansistring val variant for a zero based array if not necessary to avoid ansistring usage in embedded applications

git-svn-id: trunk@25283 -
florian 12 年之前
父節點
當前提交
a2a405581c
共有 2 個文件被更改,包括 9 次插入2 次删除
  1. 3 2
      compiler/ninl.pas
  2. 6 0
      tests/webtbs/tw8148.pp

+ 3 - 2
compiler/ninl.pas

@@ -1553,8 +1553,9 @@ implementation
         { the shortstring-longint val routine by default                   }
         if (sourcepara.resultdef.typ = stringdef) then
           procname := procname + tstringdef(sourcepara.resultdef).stringtypname
-        { zero-based arrays (of char) can be implicitely converted to ansistring }
-        else if is_zero_based_array(sourcepara.resultdef) then
+        { zero-based arrays (of char) can be implicitely converted to ansistring, but don't do
+          so if not needed because the array is too short }
+        else if is_zero_based_array(sourcepara.resultdef) and (sourcepara.resultdef.size>255) then
           procname := procname + 'ansistr'
         else
           procname := procname + 'shortstr';

+ 6 - 0
tests/webtbs/tw8148.pp

@@ -13,8 +13,10 @@ var
   Code : Integer;
   D : Double;
   s : Array[byte] of Char;
+  s2 : Array[0..100] of Char;
 begin
   s := '123';
+  s2 := '123';
   test(s);
   Val(s, D, Code); // compiles only in delphi
   if (abs(d-123.0) > 0.00001) then
@@ -22,4 +24,8 @@ begin
   Val(PChar(@s), D, Code); // compiles in both delphi and FPC
   if (abs(d-123.0) > 0.00001) then
     halt(1);
+  Val(s2, D, Code); // compiles only in delphi
+  if (abs(d-123.0) > 0.00001) then
+    halt(1);
+  writeln('ok');
 end.