io/source/TextInputStream/TextInputStream.cxx |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

New commits:
commit bf6d1e58031c56dbe85995572deabd35200c9c74
Author:     Baole Fang <baole.f...@gmail.com>
AuthorDate: Mon Mar 13 18:34:50 2023 -0400
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu Mar 16 09:23:33 2023 +0000

    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.gran...@collabora.co.uk>
    (cherry picked from commit 16242898da50fbf680df558cb47d1978c3304572)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148872
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

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();
 }
 

Reply via email to