diff options
author | Baole Fang <baole.fang@gmail.com> | 2023-03-13 18:34:50 -0400 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-03-14 06:47:26 +0000 |
commit | 16242898da50fbf680df558cb47d1978c3304572 (patch) | |
tree | 3a49ca3322263ce275c1a7fc55937cd755266402 /io | |
parent | 7121117d12ae87b394b6c6ed41a2d95aadedc5b7 (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>
Diffstat (limited to 'io')
-rw-r--r-- | io/source/TextInputStream/TextInputStream.cxx | 18 |
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(); } |