From 00850e3fa71cc9ebeacad65f54a98b9a79a8b183 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 11 Jul 2018 09:57:47 +0200 Subject: clean up UNO available() implementations There seems to be some confusion here. available() is actually the number of bytes that can be read without blocking, but most implementations seems to be just returning the number of bytes remaining in the stream. Since we're doing that, let's do it properly. (*) some of them were just casting, instead of clamping, which will return wrong values sometimes. (*) FileStreamWrapper_Impl/OInputStreamWrapper/OTempFileService were doing unnecessary work, instead of just asking the underlying SvStream for it's remaining size Change-Id: I3ef26e0363e989ed3e00be0fdb993e1cdeb7819f Reviewed-on: https://gerrit.libreoffice.org/57264 Tested-by: Jenkins Reviewed-by: Noel Grandin --- xmlhelp/source/cxxhelp/provider/inputstream.cxx | 8 +++++++- xmlhelp/source/cxxhelp/provider/urlparameter.cxx | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'xmlhelp') diff --git a/xmlhelp/source/cxxhelp/provider/inputstream.cxx b/xmlhelp/source/cxxhelp/provider/inputstream.cxx index 19e88810799e..e5f18bb5fcc9 100644 --- a/xmlhelp/source/cxxhelp/provider/inputstream.cxx +++ b/xmlhelp/source/cxxhelp/provider/inputstream.cxx @@ -116,7 +116,13 @@ XInputStream_impl::skipBytes( sal_Int32 SAL_CALL XInputStream_impl::available() { - return 0; + sal_uInt64 uPos; + if( osl::FileBase::E_None != m_aFile.getPos( uPos ) ) + throw io::IOException(); + sal_uInt64 uSize; + if( osl::FileBase::E_None != m_aFile.getSize( uSize ) ) + throw io::IOException(); + return std::min(SAL_MAX_INT32, uSize - uPos); } diff --git a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx index fb0aa90cb62b..8ed8f80a1c69 100644 --- a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx +++ b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx @@ -924,7 +924,7 @@ void SAL_CALL InputStreamTransformer::skipBytes( sal_Int32 nBytesToSkip ) sal_Int32 SAL_CALL InputStreamTransformer::available() { osl::MutexGuard aGuard( m_aMutex ); - return std::max(buffer.getLength() - pos, 0); + return std::min(SAL_MAX_INT32, buffer.getLength() - pos); } -- cgit