diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qa/cppunit/test_stream.cxx | 12 | ||||
-rw-r--r-- | tools/source/stream/stream.cxx | 34 |
2 files changed, 18 insertions, 28 deletions
diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx index b58d1f07aaa5..d8e4d1ef71e1 100644 --- a/tools/qa/cppunit/test_stream.cxx +++ b/tools/qa/cppunit/test_stream.cxx @@ -84,6 +84,18 @@ namespace //yet, the read didn't succeed CPPUNIT_ASSERT(!aMemStream.good()); + //set things up so that there is only one byte available on an attempt + //to read a two-byte sal_uInt16. The byte should be consumed, but the + //operation should fail, and tools_b should remain unchanged, + sal_uInt16 tools_b = 0x1122; + aMemStream.SeekRel(-1); + CPPUNIT_ASSERT(!aMemStream.eof()); + CPPUNIT_ASSERT(aMemStream.good()); + aMemStream.ReadUInt16( tools_b ); + CPPUNIT_ASSERT(!aMemStream.good()); + CPPUNIT_ASSERT(aMemStream.eof()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0x1122), tools_b); + iss.clear(); iss.seekg(0); CPPUNIT_ASSERT(iss.good()); diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 0feae91ece83..f807a56cf52f 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -527,8 +527,6 @@ bool SvStream::ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead ) bool SvStream::ReadUniStringLine( OUString& rStr, sal_Int32 nMaxCodepointsToRead ) { - if (!good()) - throw SvStreamEOFException(); sal_Unicode buf[256+1]; bool bEnd = false; sal_uInt64 nOldFilePos = Tell(); @@ -821,8 +819,6 @@ sal_uInt64 SvStream::SeekRel(sal_Int64 const nPos) SvStream& SvStream::ReadUInt16(sal_uInt16& r) { - if (remainingSize() < 2) - throw SvStreamEOFException(); sal_uInt16 n = 0; readNumberWithoutSwap(n); if (good()) @@ -836,8 +832,6 @@ SvStream& SvStream::ReadUInt16(sal_uInt16& r) SvStream& SvStream::ReadUInt32(sal_uInt32& r) { - if (remainingSize() < 4) - throw SvStreamEOFException(); sal_uInt32 n = 0; readNumberWithoutSwap(n); if (good()) @@ -851,8 +845,6 @@ SvStream& SvStream::ReadUInt32(sal_uInt32& r) SvStream& SvStream::ReadUInt64(sal_uInt64& r) { - if (remainingSize() < 8) - throw SvStreamEOFException(); sal_uInt64 n = 0; readNumberWithoutSwap(n); if (good()) @@ -866,8 +858,6 @@ SvStream& SvStream::ReadUInt64(sal_uInt64& r) SvStream& SvStream::ReadInt16(sal_Int16& r) { - if (remainingSize() < 2) - throw SvStreamEOFException(); sal_Int16 n = 0; readNumberWithoutSwap(n); if (good()) @@ -881,8 +871,6 @@ SvStream& SvStream::ReadInt16(sal_Int16& r) SvStream& SvStream::ReadInt32(sal_Int32& r) { - if (remainingSize() < 4) - throw SvStreamEOFException(); sal_Int32 n = 0; readNumberWithoutSwap(n); if (good()) @@ -896,13 +884,14 @@ SvStream& SvStream::ReadInt32(sal_Int32& r) SvStream& SvStream::ReadInt64(sal_Int64& r) { - if (remainingSize() < 8) - throw SvStreamEOFException(); sal_Int64 n = 0; readNumberWithoutSwap(n); - if (m_isSwap) - SwapInt64(n); - r = n; + if (good()) + { + if (m_isSwap) + SwapInt64(n); + r = n; + } return *this; } @@ -952,8 +941,6 @@ SvStream& SvStream::ReadUChar( unsigned char& r ) SvStream& SvStream::ReadUtf16(sal_Unicode& r) { - if (remainingSize() < 2) - throw SvStreamEOFException(); sal_uInt16 n = 0; readNumberWithoutSwap(n); if (good()) @@ -990,8 +977,6 @@ SvStream& SvStream::ReadCharAsBool( bool& r ) SvStream& SvStream::ReadFloat(float& r) { - if (remainingSize() < 4) - throw SvStreamEOFException(); float n = 0; readNumberWithoutSwap(n); if (good()) @@ -1007,8 +992,6 @@ SvStream& SvStream::ReadFloat(float& r) SvStream& SvStream::ReadDouble(double& r) { - if (remainingSize() < 8) - throw SvStreamEOFException(); double n = 0; readNumberWithoutSwap(n); if (good()) @@ -2149,9 +2132,4 @@ std::size_t write_uInt16_lenPrefixed_uInt8s_FromOString(SvStream& rStrm, return nWritten; } -const char * SvStreamEOFException::what() const throw() -{ - return "SvStreamEOFException"; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |