From ba46f32c804e665741a6db6f2578a01045304d14 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Sun, 30 Mar 2014 22:31:53 +0200 Subject: deploy some asserts to detect truncated STREAM_SEEK_TO_END Since STREAM_SEEK_TO_END is now 64 bits it could happen that some existing code uses it in some indirect manner and it gets truncated to 32 bits somewhere (on 32 bit platforms); try to detect that with asserts. Of course the checked value is now a valid stream position, so perhaps the checks should eventually be removed. Change-Id: I4248c00d758220bdc3ee94c7aa7a7bd4c86c57f0 --- tools/source/stream/stream.cxx | 6 ++++++ tools/source/stream/strmunx.cxx | 2 ++ tools/source/stream/strmwnt.cxx | 2 ++ 3 files changed, 10 insertions(+) (limited to 'tools') diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 48cae55f0169..9921d6f8a4dc 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -308,6 +308,8 @@ ErrCode SvAsyncLockBytes::FillAppend(const void * pBuffer, sal_Size nCount, // virtual sal_uInt64 SvAsyncLockBytes::Seek(sal_uInt64 const nPos) { + // check if a truncated STREAM_SEEK_TO_END was passed + assert(nPos != (sal_uInt64)(sal_uInt32)STREAM_SEEK_TO_END); if (nPos != STREAM_SEEK_TO_END) m_nSize = nPos; return m_nSize; @@ -343,6 +345,8 @@ sal_Size SvStream::PutData( const void* pData, sal_Size nSize ) sal_uInt64 SvStream::SeekPos(sal_uInt64 const nPos) { + // check if a truncated STREAM_SEEK_TO_END was passed + assert(nPos != (sal_uInt64)(sal_uInt32)STREAM_SEEK_TO_END); if( !GetError() && nPos == STREAM_SEEK_TO_END ) { DBG_ASSERT( xLockBytes.Is(), "pure virtual function" ); @@ -1839,6 +1843,8 @@ sal_uInt64 SvMemoryStream::SeekPos(sal_uInt64 const nNewPos) // nEndOfData: First position in stream not allowed to read from // nSize: Size of allocated buffer + // check if a truncated STREAM_SEEK_TO_END was passed + assert(nNewPos != (sal_uInt64)(sal_uInt32)STREAM_SEEK_TO_END); if( nNewPos < nEndOfData ) nPos = nNewPos; else if( nNewPos == STREAM_SEEK_TO_END ) diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx index 010bcc6660c6..c3144ed3bd57 100644 --- a/tools/source/stream/strmunx.cxx +++ b/tools/source/stream/strmunx.cxx @@ -358,6 +358,8 @@ sal_Size SvFileStream::PutData( const void* pData, sal_Size nSize ) sal_uInt64 SvFileStream::SeekPos(sal_uInt64 const nPos) { + // check if a truncated STREAM_SEEK_TO_END was passed + assert(nPos != (sal_uInt64)(sal_uInt32)STREAM_SEEK_TO_END); if ( IsOpen() ) { oslFileError rc; diff --git a/tools/source/stream/strmwnt.cxx b/tools/source/stream/strmwnt.cxx index d5f519fcef05..ad4f1336339b 100644 --- a/tools/source/stream/strmwnt.cxx +++ b/tools/source/stream/strmwnt.cxx @@ -162,6 +162,8 @@ sal_Size SvFileStream::PutData( const void* pData, sal_Size nSize ) sal_uInt64 SvFileStream::SeekPos(sal_uInt64 const nPos) { + // check if a truncated STREAM_SEEK_TO_END was passed + assert(nPos != (sal_uInt64)(sal_uInt32)STREAM_SEEK_TO_END); DWORD nNewPos = 0; if( IsOpen() ) { -- cgit v1.2.3