summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-07-18 11:28:34 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-07-18 13:09:51 +0200
commitfd2e907e448991e5c8b54acbe7e31bff24c8e875 (patch)
treefb5fcca1568589e4f430259ae3f451bf7eaf148b
parentaaebfb9baf53e4ed221a9bb8e1772fcbb7b921ab (diff)
comphelper::ByteWriter::writeSomeBytes always writes all bytes
...so rename it to writeBytes for clarity, and drop the redundant return value. Also clarify that it has a narrow interface and requires nBytesToWrite to be non-negative. Change-Id: I76dee83fecd6350f473f55dcffb950c16aa22d93 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137169 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--comphelper/source/misc/storagehelper.cxx2
-rw-r--r--comphelper/source/streaming/memorystream.cxx9
-rw-r--r--include/comphelper/bytereader.hxx2
-rw-r--r--package/source/xstor/owriteablestream.cxx12
-rw-r--r--package/source/xstor/owriteablestream.hxx2
5 files changed, 15 insertions, 12 deletions
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx
index 5f8527bcf273..934261b0c500 100644
--- a/comphelper/source/misc/storagehelper.cxx
+++ b/comphelper/source/misc/storagehelper.cxx
@@ -194,7 +194,7 @@ void OStorageHelper::CopyInputToOutput(
do
{
nRead = pByteReader->readSomeBytes ( aTempBuf, nConstBufferSize );
- pByteWriter->writeSomeBytes ( aTempBuf, nRead );
+ pByteWriter->writeBytes ( aTempBuf, nRead );
}
while ( nRead == nConstBufferSize );
}
diff --git a/comphelper/source/streaming/memorystream.cxx b/comphelper/source/streaming/memorystream.cxx
index 8bf3c3e90f5c..58380eb60d1e 100644
--- a/comphelper/source/streaming/memorystream.cxx
+++ b/comphelper/source/streaming/memorystream.cxx
@@ -18,6 +18,7 @@
*/
#include <algorithm>
+#include <cassert>
#include <memory>
#include <boost/core/noinit_adaptor.hpp>
@@ -93,7 +94,7 @@ public:
virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
// comphelper::ByteWriter
- virtual sal_Int32 writeSomeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) override;
+ virtual void writeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) override;
private:
std::vector< sal_Int8, boost::noinit_adaptor<std::allocator<sal_Int8>> > maData;
@@ -226,10 +227,11 @@ void SAL_CALL UNOMemoryStream::writeBytes( const Sequence< sal_Int8 >& aData )
mnCursor += nBytesToWrite;
}
-sal_Int32 UNOMemoryStream::writeSomeBytes( const sal_Int8* pInData, sal_Int32 nBytesToWrite )
+void UNOMemoryStream::writeBytes( const sal_Int8* pInData, sal_Int32 nBytesToWrite )
{
+ assert(nBytesToWrite >= 0);
if( !nBytesToWrite )
- return 0;
+ return;
sal_Int64 nNewSize = static_cast<sal_Int64>(mnCursor) + nBytesToWrite;
if( nNewSize > SAL_MAX_INT32 )
@@ -247,7 +249,6 @@ sal_Int32 UNOMemoryStream::writeSomeBytes( const sal_Int8* pInData, sal_Int32 nB
memcpy(pCursor, pInData, nBytesToWrite);
mnCursor += nBytesToWrite;
- return nBytesToWrite;
}
void SAL_CALL UNOMemoryStream::flush()
diff --git a/include/comphelper/bytereader.hxx b/include/comphelper/bytereader.hxx
index a7e899098846..49d683f233b8 100644
--- a/include/comphelper/bytereader.hxx
+++ b/include/comphelper/bytereader.hxx
@@ -34,7 +34,7 @@ class COMPHELPER_DLLPUBLIC ByteWriter
{
public:
virtual ~ByteWriter();
- virtual sal_Int32 writeSomeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) = 0;
+ virtual void writeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) = 0;
static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();
};
diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx
index 6ecdb35b848f..e380d971c770 100644
--- a/package/source/xstor/owriteablestream.cxx
+++ b/package/source/xstor/owriteablestream.cxx
@@ -17,8 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include <memory>
#include <sal/config.h>
+
+#include <cassert>
+#include <memory>
#include <sal/log.hxx>
#include <com/sun/star/packages/NoEncryptionException.hpp>
@@ -2099,8 +2101,10 @@ void SAL_CALL OWriteStream::writeBytes( const uno::Sequence< sal_Int8 >& aData )
ModifyParentUnlockMutex_Impl( aGuard );
}
-sal_Int32 OWriteStream::writeSomeBytes( const sal_Int8* pData, sal_Int32 nBytesToWrite )
+void OWriteStream::writeBytes( const sal_Int8* pData, sal_Int32 nBytesToWrite )
{
+ assert(nBytesToWrite >= 0);
+
osl::ClearableMutexGuard aGuard(m_pData->m_xSharedMutex->GetMutex());
// the write method makes initialization itself, since it depends from the aData length
@@ -2162,7 +2166,7 @@ sal_Int32 OWriteStream::writeSomeBytes( const sal_Int8* pData, sal_Int32 nBytesT
if (xOutputTunnel)
pByteWriter = reinterpret_cast< comphelper::ByteWriter* >( xOutputTunnel->getSomething( comphelper::ByteWriter::getUnoTunnelId() ) );
if (pByteWriter)
- nBytesToWrite = pByteWriter->writeSomeBytes(pData, nBytesToWrite);
+ pByteWriter->writeBytes(pData, nBytesToWrite);
else
{
uno::Sequence<sal_Int8> aData(pData, nBytesToWrite);
@@ -2171,8 +2175,6 @@ sal_Int32 OWriteStream::writeSomeBytes( const sal_Int8* pData, sal_Int32 nBytesT
m_pImpl->m_bHasDataToFlush = true;
ModifyParentUnlockMutex_Impl( aGuard );
-
- return nBytesToWrite;
}
sal_Int64 SAL_CALL OWriteStream::getSomething( const css::uno::Sequence< sal_Int8 >& rIdentifier )
diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx
index bd429cb03c2f..9fa6c6ea0e59 100644
--- a/package/source/xstor/owriteablestream.hxx
+++ b/package/source/xstor/owriteablestream.hxx
@@ -351,7 +351,7 @@ public:
virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
// comphelper::ByteWriter
- virtual sal_Int32 writeSomeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) override;
+ virtual void writeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) override;
};