summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaole Fang <baole.fang@gmail.com>2023-03-13 18:34:50 -0400
committerAndras Timar <andras.timar@collabora.com>2023-04-02 23:38:06 +0200
commite89ec1e4e3b7e93490226737c38298e7faf8298c (patch)
treee593d5f337168d6e0deb8949e6eaeb61b3c886bb
parent0f0d095e45293efbad0182b86f93ae09d892bf9d (diff)
tdf#150135: Fix OTextInputStream to throw runtime exception when uninitialized
New method checkNull is added to the class to throw a runtime error if mxStream is uninitialized. It is run in the beginning of all methods that require an initialized mxStream. Change-Id: Ia1f15d90c79c71b2a2350d9b60ef1bf68fb9009c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148819 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> (cherry picked from commit 16242898da50fbf680df558cb47d1978c3304572) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148872 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r--io/source/TextInputStream/TextInputStream.cxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/io/source/TextInputStream/TextInputStream.cxx b/io/source/TextInputStream/TextInputStream.cxx
index 9f7c884725cd..1ce12a6e796e 100644
--- a/io/source/TextInputStream/TextInputStream.cxx
+++ b/io/source/TextInputStream/TextInputStream.cxx
@@ -72,6 +72,8 @@ class OTextInputStream : public WeakImplHelper< XTextInputStream2, XServiceInfo
/// @throws IOException
/// @throws RuntimeException
sal_Int32 implReadNext();
+ /// @throws RuntimeException
+ void checkNull();
public:
OTextInputStream();
@@ -122,22 +124,33 @@ OTextInputStream::~OTextInputStream()
}
}
+// Check uninitialized object
+
+void OTextInputStream::checkNull()
+{
+ if (mxStream==nullptr){
+ throw RuntimeException("Uninitialized object");
+ }
+}
// XTextInputStream
OUString OTextInputStream::readLine( )
{
+ checkNull();
static Sequence< sal_Unicode > aDummySeq;
return implReadString( aDummySeq, true, true );
}
OUString OTextInputStream::readString( const Sequence< sal_Unicode >& Delimiters, sal_Bool bRemoveDelimiter )
{
+ checkNull();
return implReadString( Delimiters, bRemoveDelimiter, false );
}
sal_Bool OTextInputStream::isEOF()
{
+ checkNull();
bool bRet = false;
if( mnCharsInBuffer == 0 && mbReachedEOF )
bRet = true;
@@ -337,26 +350,31 @@ void OTextInputStream::setEncoding( const OUString& Encoding )
sal_Int32 OTextInputStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
{
+ checkNull();
return mxStream->readBytes( aData, nBytesToRead );
}
sal_Int32 OTextInputStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
{
+ checkNull();
return mxStream->readSomeBytes( aData, nMaxBytesToRead );
}
void OTextInputStream::skipBytes( sal_Int32 nBytesToSkip )
{
+ checkNull();
mxStream->skipBytes( nBytesToSkip );
}
sal_Int32 OTextInputStream::available( )
{
+ checkNull();
return mxStream->available();
}
void OTextInputStream::closeInput( )
{
+ checkNull();
mxStream->closeInput();
}