From a2a405581cd0692e17e8658562c63ac1935795e5 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 18 Aug 2013 17:04:06 +0000 Subject: [PATCH] * 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 - --- compiler/ninl.pas | 5 +++-- tests/webtbs/tw8148.pp | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/ninl.pas b/compiler/ninl.pas index 224edde123..61e6831e08 100644 --- a/compiler/ninl.pas +++ b/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'; diff --git a/tests/webtbs/tw8148.pp b/tests/webtbs/tw8148.pp index 444f6843bb..bebb85932f 100644 --- a/tests/webtbs/tw8148.pp +++ b/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.