From 50c48349d58334c8a1bbb469b25fecdd41667468 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 10 Jun 2020 20:47:58 +0000 Subject: [PATCH] * check properly for i/o errors in the iso read helpers, resolves #37154 * CheckRead checks if reading caused an I/O error and returns false in this case git-svn-id: trunk@45635 - --- .gitattributes | 1 + rtl/inc/text.inc | 58 +++++++++++++++++++++++++++++------------ tests/webtbs/tw37154.pp | 11 ++++++++ 3 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 tests/webtbs/tw37154.pp diff --git a/.gitattributes b/.gitattributes index 7fc1e0be0c..f7ff193b28 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18323,6 +18323,7 @@ tests/webtbs/tw37095.pp svneol=native#text/plain tests/webtbs/tw37095d/uw37095.pp svneol=native#text/plain tests/webtbs/tw37107.pp svneol=native#text/pascal tests/webtbs/tw37136.pp svneol=native#text/pascal +tests/webtbs/tw37154.pp svneol=native#text/pascal tests/webtbs/tw3719.pp svneol=native#text/plain tests/webtbs/tw3721.pp svneol=native#text/plain tests/webtbs/tw3742.pp svneol=native#text/plain diff --git a/rtl/inc/text.inc b/rtl/inc/text.inc index 360876396a..3923f8e663 100644 --- a/rtl/inc/text.inc +++ b/rtl/inc/text.inc @@ -1457,7 +1457,7 @@ begin end; if TextRec(f).BufPos>=TextRec(f).BufEnd Then FileFunc(TextRec(f).InOutFunc)(TextRec(f)); - CheckRead:=True; + CheckRead:=InOutRes=0; end; @@ -1991,11 +1991,15 @@ var hs : String; code : ValSInt; Begin - ReadInteger(f,hs); + l:=0; + if not CheckRead(f) then + Exit; - Val(hs,l,code); - if Code <> 0 then - InOutRes:=106; + ReadInteger(f,hs); + + Val(hs,l,code); + if Code <> 0 then + InOutRes:=106; End; @@ -2031,10 +2035,14 @@ var hs : String; code : ValSInt; Begin - ReadInteger(f,hs); - Val(hs,u,code); - If code<>0 Then - InOutRes:=106; + u:=0; + if not CheckRead(f) then + Exit; + + ReadInteger(f,hs); + Val(hs,u,code); + If code<>0 Then + InOutRes:=106; End; @@ -2067,6 +2075,10 @@ var hs : string; code : Word; begin + v:=0.0; + if not CheckRead(f) then + Exit; + ReadReal(f,hs); Val(hs,v,code); If code<>0 Then @@ -2127,6 +2139,10 @@ var hs : string; code : ValSInt; begin + v:=0.0; + if not CheckRead(f) then + Exit; + ReadReal(f,hs); Val(hs,v,code); If code<>0 Then @@ -2163,10 +2179,14 @@ var hs : String; code : longint; Begin - ReadInteger(f,hs); - Val(hs,q,code); - If code<>0 Then - InOutRes:=106; + q:=0; + if not CheckRead(f) then + Exit; + + ReadInteger(f,hs); + Val(hs,q,code); + If code<>0 Then + InOutRes:=106; End; procedure fpc_Read_Text_Int64(var f : text; out i : int64); iocheck; compilerproc; @@ -2196,10 +2216,14 @@ var hs : String; code : Longint; Begin - ReadInteger(f,hs); - Val(hs,i,code); - If code<>0 Then - InOutRes:=106; + l:=0; + if not CheckRead(f) then + Exit; + + ReadInteger(f,hs); + Val(hs,i,code); + If code<>0 Then + InOutRes:=106; End; diff --git a/tests/webtbs/tw37154.pp b/tests/webtbs/tw37154.pp new file mode 100644 index 0000000000..8d675a53cd --- /dev/null +++ b/tests/webtbs/tw37154.pp @@ -0,0 +1,11 @@ +{ %RESULT=6 } +{$mode ISO} +program isoModeReadingNumbers(input, output); +var + i: integer; +begin + { we cannot call the executable with <&- >&- while running the test suite, + so render the file handle manually illegal } + Textrec(input).handle:=$1234; + readLn(i); +end.