diff options
-rw-r--r-- | comphelper/source/misc/base64.cxx | 21 | ||||
-rw-r--r-- | include/comphelper/base64.hxx | 8 | ||||
-rw-r--r-- | tools/source/fsys/urlobj.cxx | 2 |
3 files changed, 20 insertions, 11 deletions
diff --git a/comphelper/source/misc/base64.cxx b/comphelper/source/misc/base64.cxx index d73465601adb..e4a818011332 100644 --- a/comphelper/source/misc/base64.cxx +++ b/comphelper/source/misc/base64.cxx @@ -17,10 +17,15 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <cstddef> + #include <comphelper/base64.hxx> #include <com/sun/star/uno/Sequence.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> using namespace com::sun::star; @@ -138,26 +143,26 @@ void Base64::encode(OUStringBuffer& aStrBuffer, const uno::Sequence<sal_Int8>& a void Base64::decode(uno::Sequence<sal_Int8>& aBuffer, std::u16string_view sBuffer) { - sal_Int32 nCharsDecoded = decodeSomeChars( aBuffer, sBuffer ); - OSL_ENSURE( sal_uInt32(nCharsDecoded) == sBuffer.size(), "some bytes left in base64 decoding!" ); + std::size_t nCharsDecoded = decodeSomeChars( aBuffer, sBuffer ); + OSL_ENSURE( nCharsDecoded == sBuffer.size(), "some bytes left in base64 decoding!" ); } -sal_Int32 Base64::decodeSomeChars(uno::Sequence<sal_Int8>& rOutBuffer, std::u16string_view rInBuffer) +std::size_t Base64::decodeSomeChars(uno::Sequence<sal_Int8>& rOutBuffer, std::u16string_view rInBuffer) { - sal_Int32 nInBufferLen = rInBuffer.size(); - sal_Int32 nMinOutBufferLen = (nInBufferLen / 4) * 3; - if( rOutBuffer.getLength() < nMinOutBufferLen ) + std::size_t nInBufferLen = rInBuffer.size(); + std::size_t nMinOutBufferLen = (nInBufferLen / 4) * 3; + if( o3tl::make_unsigned(rOutBuffer.getLength()) < nMinOutBufferLen ) rOutBuffer.realloc( nMinOutBufferLen ); const sal_Unicode *pInBuffer = rInBuffer.data(); sal_Int8 *pOutBuffer = rOutBuffer.getArray(); sal_Int8 *pOutBufferStart = pOutBuffer; - sal_Int32 nCharsDecoded = 0; + std::size_t nCharsDecoded = 0; sal_uInt8 aDecodeBuffer[4]; sal_Int32 nBytesToDecode = 0; sal_Int32 nBytesGotFromDecoding = 3; - sal_Int32 nInBufferPos= 0; + std::size_t nInBufferPos= 0; while( nInBufferPos < nInBufferLen ) { sal_Unicode cChar = *pInBuffer; diff --git a/include/comphelper/base64.hxx b/include/comphelper/base64.hxx index ed32b2f8bc0e..78a0bacb58e7 100644 --- a/include/comphelper/base64.hxx +++ b/include/comphelper/base64.hxx @@ -20,6 +20,10 @@ #ifndef INCLUDED_COMPHELPER_BASE64_HXX #define INCLUDED_COMPHELPER_BASE64_HXX +#include <sal/config.h> + +#include <cstddef> + #include <comphelper/comphelperdllapi.h> #include <sal/types.h> @@ -48,8 +52,8 @@ public: // must be used! static void decode(css::uno::Sequence<sal_Int8>& aPass, std::u16string_view sBuffer); - static sal_Int32 decodeSomeChars(css::uno::Sequence<sal_Int8>& aPass, - std::u16string_view sBuffer); + static std::size_t decodeSomeChars(css::uno::Sequence<sal_Int8>& aPass, + std::u16string_view sBuffer); }; } diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx index 6b776ef38f31..a6f2329e281d 100644 --- a/tools/source/fsys/urlobj.cxx +++ b/tools/source/fsys/urlobj.cxx @@ -649,7 +649,7 @@ std::unique_ptr<SvMemoryStream> INetURLObject::getData() const std::u16string_view sBase64Data = sURLPath.subView( nCharactersSkipped ); css::uno::Sequence< sal_Int8 > aDecodedData; if (comphelper::Base64::decodeSomeChars(aDecodedData, sBase64Data) - == static_cast<sal_Int32>(sBase64Data.size())) + == sBase64Data.size()) { return memoryStream( aDecodedData.getArray(), aDecodedData.getLength()); |