tdf#120703 PVS: V555

V555 The expression 'xBlob->length() - nDataWritten > 0' will work as
     'xBlob->length() != nDataWritten'.

Calling XBlob::length() only once allows to avoid overhead of acquiring
mutex per each iteration.

V555 The expression 'xBytes.getLength() - nDataWritten > 0' will work
     as 'xBytes.getLength() != nDataWritten'.

Change-Id: I2e1772fe3af16ac6a6d6f5d2854e84f2fc69ff5f
Reviewed-on: https://gerrit.libreoffice.org/63243
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index bec7fdf..0fb8579 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -636,24 +636,25 @@

    openBlobForWriting(aBlobHandle, aBlobId);

    // Max segment size is 2^16 == SAL_MAX_UINT16
    // LEM TODO: SAL_MAX_UINT16 is 2^16-1; this mixup is probably innocuous; to be checked
    sal_uInt64 nDataWritten = 0;
    ISC_STATUS aErr = 0;
    while (xBlob->length() - nDataWritten > 0)
    const sal_Int64 nBlobLen = xBlob->length();
    if (nBlobLen > 0)
    {
        sal_uInt64 nDataRemaining = xBlob->length() - nDataWritten;
        sal_uInt16 nWriteSize = std::min<sal_uInt64>(nDataRemaining, SAL_MAX_UINT16);
        aErr = isc_put_segment(m_statusVector,
                               &aBlobHandle,
                               nWriteSize,
                               reinterpret_cast<const char*>(xBlob->getBytes(nDataWritten, nWriteSize).getConstArray()));
        nDataWritten += nWriteSize;
        // Max write size is 0xFFFF == SAL_MAX_UINT16
        sal_uInt64 nDataWritten = 0;
        while (sal::static_int_cast<sal_uInt64>(nBlobLen) > nDataWritten)
        {
            sal_uInt64 nDataRemaining = nBlobLen - nDataWritten;
            sal_uInt16 nWriteSize = std::min(nDataRemaining, sal_uInt64(SAL_MAX_UINT16));
            aErr = isc_put_segment(m_statusVector,
                                   &aBlobHandle,
                                   nWriteSize,
                                   reinterpret_cast<const char*>(xBlob->getBytes(nDataWritten, nWriteSize).getConstArray()));
            nDataWritten += nWriteSize;


        if (aErr)
            break;

            if (aErr)
                break;
        }
    }

    // We need to make sure we close the Blob even if their are errors, hence evaluate
@@ -802,21 +803,25 @@

        openBlobForWriting(aBlobHandle, aBlobId);

        // Max segment size is 2^16 == SAL_MAX_UINT16
        sal_uInt64 nDataWritten = 0;
        ISC_STATUS aErr = 0;
        while (xBytes.getLength() - nDataWritten > 0)
        const sal_Int32 nBytesLen = xBytes.getLength();
        if (nBytesLen > 0)
        {
            sal_uInt64 nDataRemaining = xBytes.getLength() - nDataWritten;
            sal_uInt16 nWriteSize = std::min<sal_uInt64>(nDataRemaining, SAL_MAX_UINT16);
            aErr = isc_put_segment(m_statusVector,
                                   &aBlobHandle,
                                   nWriteSize,
                                   reinterpret_cast<const char*>(xBytes.getConstArray()) + nDataWritten);
            nDataWritten += nWriteSize;
            // Max write size is 0xFFFF == SAL_MAX_UINT16
            sal_uInt32 nDataWritten = 0;
            while (sal::static_int_cast<sal_uInt32>(nBytesLen) > nDataWritten)
            {
                sal_uInt32 nDataRemaining = nBytesLen - nDataWritten;
                sal_uInt16 nWriteSize = std::min(nDataRemaining, sal_uInt32(SAL_MAX_UINT16));
                aErr = isc_put_segment(m_statusVector,
                                       &aBlobHandle,
                                       nWriteSize,
                                       reinterpret_cast<const char*>(xBytes.getConstArray()) + nDataWritten);
                nDataWritten += nWriteSize;

            if (aErr)
                break;
                if (aErr)
                    break;
            }
        }

        // We need to make sure we close the Blob even if their are errors, hence evaluate