From a8a1bb6449cab8f4ab8f14e9914fec0fdd59262a Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sat, 26 Jan 2013 19:27:17 +0000 Subject: [PATCH] * fixed inserting something in a shortstring past its maximum length (mantis #23744) git-svn-id: trunk@23524 - --- .gitattributes | 1 + rtl/inc/sstrings.inc | 12 ++++++++++-- tests/webtbs/tw23744.pp | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/webtbs/tw23744.pp diff --git a/.gitattributes b/.gitattributes index f7c776e047..c62a5124a2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13155,6 +13155,7 @@ tests/webtbs/tw23486.pp svneol=native#text/pascal tests/webtbs/tw23503.pp svneol=native#text/pascal tests/webtbs/tw2351.pp svneol=native#text/plain tests/webtbs/tw2363.pp svneol=native#text/plain +tests/webtbs/tw23744.pp svneol=native#text/plain tests/webtbs/tw2377.pp svneol=native#text/plain tests/webtbs/tw2378.pp svneol=native#text/plain tests/webtbs/tw2382.pp svneol=native#text/plain diff --git a/rtl/inc/sstrings.inc b/rtl/inc/sstrings.inc index 5960492078..2adf56618f 100644 --- a/rtl/inc/sstrings.inc +++ b/rtl/inc/sstrings.inc @@ -74,7 +74,11 @@ begin if index<1 then index:=1; if index>length(s) then - index:=length(s)+1; + begin + index:=length(s)+1; + if index>high(s) then + exit; + end; indexlen:=Length(s)-Index+1; srclen:=length(Source); if sizeInt(length(source))+sizeint(length(s))>=sizeof(s) then @@ -104,7 +108,11 @@ begin if index<1 then index:=1; if index>length(s) then - index:=length(s)+1; + begin + index:=length(s)+1; + if index>high(s) then + exit; + end; indexlen:=Length(s)-Index+1; if (sizeint(length(s))+1=sizeof(s)) and (indexlen>0) then dec(indexlen); diff --git a/tests/webtbs/tw23744.pp b/tests/webtbs/tw23744.pp new file mode 100644 index 0000000000..50aea98983 --- /dev/null +++ b/tests/webtbs/tw23744.pp @@ -0,0 +1,15 @@ +var + S:String[16]; + C:Char = '?'; + inss: string = 'abc'; +begin + S:='DefineTestString'; + Insert(C,S,20); + if (length(s)>16) or + (s<>'DefineTestString') then + halt(1); + insert(inss,s,20); + if (length(s)>16) or + (s<>'DefineTestString') then + halt(2); +end.