From 130d9fee91b5e0b68378457ea1a94ec96dfd5166 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 1 May 2016 12:35:09 +0000 Subject: [PATCH] * don't take the address of element 0 of a dynamic array in tcallparanode.copy_value_by_ref_para() if the array is empty (mantis #30007) git-svn-id: trunk@33595 - --- .gitattributes | 1 + compiler/ncal.pas | 22 +++++++++++++++------- tests/webtbs/tw30007.pp | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 tests/webtbs/tw30007.pp diff --git a/.gitattributes b/.gitattributes index 7411e766bd..67e124fc0f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15038,6 +15038,7 @@ tests/webtbs/tw29958.pp svneol=native#text/pascal tests/webtbs/tw2998.pp svneol=native#text/plain tests/webtbs/tw2999.pp svneol=native#text/plain tests/webtbs/tw29992.pp svneol=native#text/plain +tests/webtbs/tw30007.pp svneol=native#text/plain tests/webtbs/tw30030.pp svneol=native#text/pascal tests/webtbs/tw30035.pp svneol=native#text/plain tests/webtbs/tw30035a.pp svneol=native#text/plain diff --git a/compiler/ncal.pas b/compiler/ncal.pas index e6292dfb6a..9340c038d0 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -303,7 +303,7 @@ implementation verbose,globals, symconst,defutil,defcmp, htypechk,pass_1, - ncnv,nld,ninl,nadd,ncon,nmem,nset,nobjc, + ncnv,nflw,nld,ninl,nadd,ncon,nmem,nset,nobjc, ngenutil,objcutil, procinfo,cpuinfo, wpobase; @@ -765,16 +765,24 @@ implementation { move(para,temp,sizeof(arr)) (no "left.getcopy" below because we replace left afterwards) } addstatement(initstat, - ccallnode.createintern('MOVE', - ccallparanode.create( - arraysize, + cifnode.create_internal( + caddnode.create_internal( + unequaln, + arraysize.getcopy, + genintconstnode(0) + ), + ccallnode.createintern('MOVE', ccallparanode.create( - cderefnode.create(ctemprefnode.create(paratemp)), + arraysize, ccallparanode.create( - arraybegin,nil + cderefnode.create(ctemprefnode.create(paratemp)), + ccallparanode.create( + arraybegin,nil + ) ) ) - ) + ), + nil ) ); { no reference count increases, that's still done on the callee diff --git a/tests/webtbs/tw30007.pp b/tests/webtbs/tw30007.pp new file mode 100644 index 0000000000..41d10c152d --- /dev/null +++ b/tests/webtbs/tw30007.pp @@ -0,0 +1,16 @@ +program project6; + +{$r+} + +function LinesToText(Lines: array of String): String; +begin +end; + +var + SomeLines: array of String; +begin + SetLength(SomeLines,1); + LinesToText(SomeLines); // <-- ok + SetLength(SomeLines,0); + LinesToText(SomeLines); // <-- range error +end.