summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-11-10 19:46:00 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2018-11-11 08:48:43 +0100
commit25ddf69517134305d4dffd5dc1d111fe74584fac (patch)
tree9bb1a7499f37429038ed179b6eb99e6dcae17270 /connectivity
parent30df4a32449f3b717e77eb447583730e026b7d17 (diff)
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>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.cxx61
1 files changed, 33 insertions, 28 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index bec7fdfe02a8..0fb8579b0894 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -636,24 +636,25 @@ void SAL_CALL OPreparedStatement::setBlob(sal_Int32 nParameterIndex,
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;
-
-
- if (aErr)
- break;
+ // 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;
+ }
}
// We need to make sure we close the Blob even if their are errors, hence evaluate
@@ -802,21 +803,25 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex,
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;
-
- if (aErr)
- break;
+ // 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;
+ }
}
// We need to make sure we close the Blob even if their are errors, hence evaluate