From 2e9aecb160af8637a8f90aa5ee7b86572e5800e0 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Thu, 5 Oct 2017 18:25:08 -0500 Subject: [PATCH] eliminate VS implicit conversion warnings --- Crypto/src/ECKeyImpl.cpp | 4 ++-- Data/SQLite/src/Binder.cpp | 2 +- Data/SQLite/src/Extractor.cpp | 2 +- Data/SQLite/src/SQLiteStatementImpl.cpp | 2 +- Data/SQLite/src/SessionImpl.cpp | 4 ++-- Data/testsuite/src/DataTest.cpp | 2 +- MongoDB/src/Document.cpp | 2 +- MongoDB/testsuite/src/MongoDBTest.cpp | 2 +- NetSSL_OpenSSL/testsuite/src/WebSocketTest.cpp | 2 +- NetSSL_Win/src/SecureSocketImpl.cpp | 6 +++--- NetSSL_Win/src/X509Certificate.cpp | 2 +- NetSSL_Win/testsuite/src/WebSocketTest.cpp | 2 +- Redis/src/RedisStream.cpp | 4 ++-- Redis/testsuite/src/RedisTest.cpp | 4 ++-- XML/src/xmlparse.cpp | 7 ++++--- Zip/src/AutoDetectStream.cpp | 10 +++++----- Zip/src/PartialStream.cpp | 17 +++++++++-------- Zip/src/ZipStream.cpp | 12 ++++++------ 18 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Crypto/src/ECKeyImpl.cpp b/Crypto/src/ECKeyImpl.cpp index edc50c604..ad4888543 100644 --- a/Crypto/src/ECKeyImpl.cpp +++ b/Crypto/src/ECKeyImpl.cpp @@ -184,7 +184,7 @@ std::string ECKeyImpl::getCurveName(int nid) std::string curveName; size_t len = EC_get_builtin_curves(NULL, 0); EC_builtin_curve* pCurves = - (EC_builtin_curve*) OPENSSL_malloc(sizeof(EC_builtin_curve) * len); + (EC_builtin_curve*) OPENSSL_malloc(static_cast(sizeof(EC_builtin_curve) * len)); if (!pCurves) return curveName; if (!EC_get_builtin_curves(pCurves, len)) @@ -209,7 +209,7 @@ int ECKeyImpl::getCurveNID(std::string& name) std::string curveName; size_t len = EC_get_builtin_curves(NULL, 0); EC_builtin_curve* pCurves = - (EC_builtin_curve*)OPENSSL_malloc(sizeof(EC_builtin_curve) * len); + (EC_builtin_curve*)OPENSSL_malloc(static_cast(sizeof(EC_builtin_curve) * len)); if (!pCurves) return -1; if (!EC_get_builtin_curves(pCurves, len)) diff --git a/Data/SQLite/src/Binder.cpp b/Data/SQLite/src/Binder.cpp index f47fe358a..9849ad03c 100644 --- a/Data/SQLite/src/Binder.cpp +++ b/Data/SQLite/src/Binder.cpp @@ -113,7 +113,7 @@ void Binder::bind(std::size_t pos, const DateTime& val, Direction dir, const Whe void Binder::bind(std::size_t pos, const NullData&, Direction, const std::type_info& bindType) { - sqlite3_bind_null(_pStmt, pos); + sqlite3_bind_null(_pStmt, static_cast(pos)); } diff --git a/Data/SQLite/src/Extractor.cpp b/Data/SQLite/src/Extractor.cpp index 3af5d28ca..dc027ffca 100644 --- a/Data/SQLite/src/Extractor.cpp +++ b/Data/SQLite/src/Extractor.cpp @@ -228,7 +228,7 @@ bool Extractor::isNull(std::size_t pos, std::size_t) if (!_nulls[pos].first) { _nulls[pos].first = true; - _nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, pos)); + _nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, static_cast(pos))); } return _nulls[pos].second; diff --git a/Data/SQLite/src/SQLiteStatementImpl.cpp b/Data/SQLite/src/SQLiteStatementImpl.cpp index d668ae7f7..3e637b8be 100644 --- a/Data/SQLite/src/SQLiteStatementImpl.cpp +++ b/Data/SQLite/src/SQLiteStatementImpl.cpp @@ -277,7 +277,7 @@ std::size_t SQLiteStatementImpl::next() if (_affectedRowCount == POCO_SQLITE_INV_ROW_CNT) _affectedRowCount = 0; if (extracts.size()) - _affectedRowCount += (*extracts.begin())->numOfRowsHandled(); + _affectedRowCount += static_cast((*extracts.begin())->numOfRowsHandled()); else { _stepCalled = true; diff --git a/Data/SQLite/src/SessionImpl.cpp b/Data/SQLite/src/SessionImpl.cpp index 7ce6b3146..6c26a5404 100644 --- a/Data/SQLite/src/SessionImpl.cpp +++ b/Data/SQLite/src/SessionImpl.cpp @@ -183,7 +183,7 @@ void SessionImpl::open(const std::string& connect) { ActiveConnector connector(connectionString(), &_pDB); ActiveResult result = connector.connect(); - if (!result.tryWait(getLoginTimeout() * 1000)) + if (!result.tryWait(static_cast(getLoginTimeout()) * 1000)) throw ConnectionFailedException("Timed out."); int rc = result.data(); @@ -244,7 +244,7 @@ void SessionImpl::setConnectionTimeout(std::size_t timeout) { if(timeout <= std::numeric_limits::max()/1000) { - int tout = 1000 * timeout; + int tout = 1000 * static_cast(timeout); int rc = sqlite3_busy_timeout(_pDB, tout); if (rc != 0) Utility::throwException(rc); _timeout = tout; diff --git a/Data/testsuite/src/DataTest.cpp b/Data/testsuite/src/DataTest.cpp index 650bbc39f..e5ff5e409 100644 --- a/Data/testsuite/src/DataTest.cpp +++ b/Data/testsuite/src/DataTest.cpp @@ -1177,7 +1177,7 @@ void DataTest::testSimpleRowFormatter() std::streamsize sp = rf.getSpacing(); std::string line(std::string::size_type(sz * 5 + sp * 4), '-'); - std::string spacer(sp, ' '); + std::string spacer(static_cast(sp), ' '); std::ostringstream os; os << std::left << std::setw(sz) << "field0" diff --git a/MongoDB/src/Document.cpp b/MongoDB/src/Document.cpp index 1a153589f..8f311f819 100644 --- a/MongoDB/src/Document.cpp +++ b/MongoDB/src/Document.cpp @@ -59,7 +59,7 @@ Int64 Document::getInteger(const std::string& name) const if (ElementTraits::TypeId == element->type()) { ConcreteElement* concrete = dynamic_cast*>(element.get()); - if (concrete) return concrete->value(); + if (concrete) return static_cast(concrete->value()); } else if (ElementTraits::TypeId == element->type()) { diff --git a/MongoDB/testsuite/src/MongoDBTest.cpp b/MongoDB/testsuite/src/MongoDBTest.cpp index d03324799..b3f903b52 100644 --- a/MongoDB/testsuite/src/MongoDBTest.cpp +++ b/MongoDB/testsuite/src/MongoDBTest.cpp @@ -245,7 +245,7 @@ void MongoDBTest::testCursorRequest() Poco::MongoDB::ResponseMessage& response = cursor.next(*_mongo); while(1) { - n += response.documents().size(); + n += static_cast(response.documents().size()); if ( response.cursorID() == 0 ) break; response = cursor.next(*_mongo); diff --git a/NetSSL_OpenSSL/testsuite/src/WebSocketTest.cpp b/NetSSL_OpenSSL/testsuite/src/WebSocketTest.cpp index c91cbce58..2e36d7afd 100644 --- a/NetSSL_OpenSSL/testsuite/src/WebSocketTest.cpp +++ b/NetSSL_OpenSSL/testsuite/src/WebSocketTest.cpp @@ -54,7 +54,7 @@ namespace int n; do { - n = ws.receiveFrame(pBuffer.get(), _bufSize, flags); + n = ws.receiveFrame(pBuffer.get(), static_cast(_bufSize), flags); if (n == 0) break; ws.sendFrame(pBuffer.get(), n, flags); diff --git a/NetSSL_Win/src/SecureSocketImpl.cpp b/NetSSL_Win/src/SecureSocketImpl.cpp index ee867a3a5..fbce5dd5f 100644 --- a/NetSSL_Win/src/SecureSocketImpl.cpp +++ b/NetSSL_Win/src/SecureSocketImpl.cpp @@ -435,7 +435,7 @@ int SecureSocketImpl::receiveBytes(void* buffer, int length, int flags) } else { - rc = overflowSize; + rc = static_cast(overflowSize); std::memcpy(buffer, _overflowBuffer.begin(), rc); _overflowBuffer.resize(0); } @@ -1283,7 +1283,7 @@ void SecureSocketImpl::verifyCertificateChainClient(PCCERT_CONTEXT pServerCert) BOOL ok = CertVerifyRevocation( X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, - certs.size(), + static_cast(certs.size()), (void**) &certs[0], CERT_VERIFY_REV_CHAIN_FLAG, NULL, @@ -1390,7 +1390,7 @@ void SecureSocketImpl::serverVerifyCertificate() BOOL ok = CertVerifyRevocation( X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, - certs.size(), + static_cast(certs.size()), (void**) &certs[0], CERT_VERIFY_REV_CHAIN_FLAG, NULL, diff --git a/NetSSL_Win/src/X509Certificate.cpp b/NetSSL_Win/src/X509Certificate.cpp index 084e2ed2a..9ca4f6dc2 100644 --- a/NetSSL_Win/src/X509Certificate.cpp +++ b/NetSSL_Win/src/X509Certificate.cpp @@ -233,7 +233,7 @@ void X509Certificate::extractNames(std::string& cmnName, std::set& flags |= CRYPT_DECODE_ENABLE_PUNYCODE_FLAG; #endif Poco::Buffer buffer(256); - DWORD bufferSize = buffer.sizeBytes(); + DWORD bufferSize = static_cast(buffer.sizeBytes()); BOOL rc = CryptDecodeObjectEx( X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, pExt->pszObjId, diff --git a/NetSSL_Win/testsuite/src/WebSocketTest.cpp b/NetSSL_Win/testsuite/src/WebSocketTest.cpp index e3d414c58..f4f25d884 100644 --- a/NetSSL_Win/testsuite/src/WebSocketTest.cpp +++ b/NetSSL_Win/testsuite/src/WebSocketTest.cpp @@ -54,7 +54,7 @@ namespace int n; do { - n = ws.receiveFrame(pBuffer.get(), _bufSize, flags); + n = ws.receiveFrame(pBuffer.get(), static_cast(_bufSize), flags); if (n == 0) break; ws.sendFrame(pBuffer.get(), n, flags); diff --git a/Redis/src/RedisStream.cpp b/Redis/src/RedisStream.cpp index 68d317bd1..75150e9a5 100644 --- a/Redis/src/RedisStream.cpp +++ b/Redis/src/RedisStream.cpp @@ -43,13 +43,13 @@ RedisStreamBuf::~RedisStreamBuf() int RedisStreamBuf::readFromDevice(char* buffer, std::streamsize len) { - return _redis.receiveBytes(buffer, len); + return _redis.receiveBytes(buffer, static_cast(len)); } int RedisStreamBuf::writeToDevice(const char* buffer, std::streamsize length) { - return _redis.sendBytes(buffer, length); + return _redis.sendBytes(buffer, static_cast(length)); } diff --git a/Redis/testsuite/src/RedisTest.cpp b/Redis/testsuite/src/RedisTest.cpp index 4a4f58d11..164b732e5 100644 --- a/Redis/testsuite/src/RedisTest.cpp +++ b/Redis/testsuite/src/RedisTest.cpp @@ -289,7 +289,7 @@ void RedisTest::testDECR() Poco::Int64 result = _redis.execute(decr); fail("This must fail"); } - catch (RedisException& e) + catch (RedisException&) { // ERR value is not an integer or out of range } @@ -338,7 +338,7 @@ void RedisTest::testError() BulkString result = _redis.execute(command); fail("Invalid command must throw RedisException"); } - catch (RedisException& e) + catch (RedisException&) { // Must fail } diff --git a/XML/src/xmlparse.cpp b/XML/src/xmlparse.cpp index 46df150c2..e51fb4c15 100644 --- a/XML/src/xmlparse.cpp +++ b/XML/src/xmlparse.cpp @@ -932,14 +932,15 @@ ENTROPY_DEBUG(const char * label, unsigned long entropy) { static unsigned long generate_hash_secret_salt(XML_Parser parser) { - Poco::UInt64 entropy; - (void)parser; #if defined(EXPAT_POCO) + Poco::UInt64 entropy; Poco::RandomInputStream rstr; Poco::BinaryReader rrdr(rstr); rrdr >> entropy; - return ENTROPY_DEBUG("RandomInputStream", entropy); + return ENTROPY_DEBUG("RandomInputStream", (unsigned long)entropy); #else + unsigned long entropy; + (void)parser; #if defined(HAVE_ARC4RANDOM_BUF) || defined(__CloudABI__) (void)gather_time_entropy; arc4random_buf(&entropy, sizeof(entropy)); diff --git a/Zip/src/AutoDetectStream.cpp b/Zip/src/AutoDetectStream.cpp index 266ea5de7..0743444a8 100644 --- a/Zip/src/AutoDetectStream.cpp +++ b/Zip/src/AutoDetectStream.cpp @@ -62,7 +62,7 @@ int AutoDetectStreamBuf::readFromDevice(char* buffer, std::streamsize length) std::streamsize n = (_prefix.size() > length) ? length : static_cast(_prefix.size()); std::memcpy(buffer, _prefix.data(), n); _prefix.erase(0, n); - return n; + return static_cast(n); } if (_eofDetected) @@ -72,7 +72,7 @@ int AutoDetectStreamBuf::readFromDevice(char* buffer, std::streamsize length) std::streamsize n = (_postfix.size() > length) ? length : static_cast(_postfix.size()); std::memcpy(buffer, _postfix.data(), n); _postfix.erase(0, n); - return n; + return static_cast(n); } else return -1; } @@ -135,7 +135,7 @@ int AutoDetectStreamBuf::readFromDevice(char* buffer, std::streamsize length) _postfix.erase(0, offset); } - return offset; + return static_cast(offset); } } else @@ -159,7 +159,7 @@ int AutoDetectStreamBuf::readFromDevice(char* buffer, std::streamsize length) _postfix.erase(0, offset); } - return offset; + return static_cast(offset); } } @@ -185,7 +185,7 @@ int AutoDetectStreamBuf::readFromDevice(char* buffer, std::streamsize length) } _length += offset; - return offset; + return static_cast(offset); } diff --git a/Zip/src/PartialStream.cpp b/Zip/src/PartialStream.cpp index 393826a25..7948a30e9 100644 --- a/Zip/src/PartialStream.cpp +++ b/Zip/src/PartialStream.cpp @@ -74,7 +74,7 @@ int PartialStreamBuf::readFromDevice(char* buffer, std::streamsize length) std::streamsize tmp = (_prefix.size() > length)? length: static_cast(_prefix.size()); std::memcpy(buffer, _prefix.c_str(), tmp); _prefix = _prefix.substr(tmp); - return tmp; + return static_cast(tmp); } if (_numBytes == 0) @@ -84,7 +84,7 @@ int PartialStreamBuf::readFromDevice(char* buffer, std::streamsize length) std::streamsize tmp = (_postfix.size() > length)? length: static_cast(_postfix.size()); std::memcpy(buffer, _postfix.c_str(), tmp); _postfix = _postfix.substr(tmp); - return tmp; + return static_cast(tmp); } else return -1; @@ -99,7 +99,7 @@ int PartialStreamBuf::readFromDevice(char* buffer, std::streamsize length) _pIstr->read(buffer, length); std::streamsize bytesRead = _pIstr->gcount(); _numBytes -= bytesRead; - return bytesRead; + return static_cast(bytesRead); } @@ -121,7 +121,7 @@ int PartialStreamBuf::writeToDevice(const char* buffer, std::streamsize length) { _ignoreStart -= length; // fake return values - return length; + return static_cast(length); } else { @@ -136,10 +136,10 @@ int PartialStreamBuf::writeToDevice(const char* buffer, std::streamsize length) cnt += static_cast(_ignoreStart); _ignoreStart = 0; poco_assert (cnt < length); - _bufferOffset = length - cnt; + _bufferOffset = static_cast(length - cnt); std::memcpy(_buffer.begin(), buffer + cnt, _bufferOffset); - return length; + return static_cast(length); } } if (_buffer.size() > 0) @@ -148,7 +148,8 @@ int PartialStreamBuf::writeToDevice(const char* buffer, std::streamsize length) // thus first fill the buffer with the last n bytes of the msg // how much of the already cached data do we need to write? - Poco::Int32 cache = _bufferOffset + length - _buffer.size(); + Poco::Int32 cache = static_cast(_bufferOffset + + static_cast(length) - static_cast(_buffer.size())); if (cache > 0) { if (cache > _bufferOffset) @@ -184,7 +185,7 @@ int PartialStreamBuf::writeToDevice(const char* buffer, std::streamsize length) } if (_pOstr->good()) - return length; + return static_cast(length); throw Poco::IOException("Failed to write to output stream"); } diff --git a/Zip/src/ZipStream.cpp b/Zip/src/ZipStream.cpp index 4c45e5d39..a26bab1ca 100644 --- a/Zip/src/ZipStream.cpp +++ b/Zip/src/ZipStream.cpp @@ -61,7 +61,7 @@ ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEnt std::string crc(4, ' '); if (fileEntry.searchCRCAndSizesAfterData()) { - _ptrHelper = new AutoDetectInputStream(istr, init, crc, reposition, start, fileEntry.needsZip64()); + _ptrHelper = new AutoDetectInputStream(istr, init, crc, reposition, static_cast(start), fileEntry.needsZip64()); } else { @@ -73,7 +73,7 @@ ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEnt { if (fileEntry.searchCRCAndSizesAfterData()) { - _ptrBuf = new AutoDetectInputStream(istr, "", "", reposition, start, fileEntry.needsZip64()); + _ptrBuf = new AutoDetectInputStream(istr, "", "", reposition, static_cast(start), fileEntry.needsZip64()); } else { @@ -155,7 +155,7 @@ int ZipStreamBuf::readFromDevice(char* buffer, std::streamsize length) { if (!_ptrBuf) return 0; // directory entry _ptrBuf->read(buffer, length); - int cnt = _ptrBuf->gcount(); + int cnt = static_cast(_ptrBuf->gcount()); if (cnt > 0) { _crc32.update(buffer, cnt); @@ -193,14 +193,14 @@ int ZipStreamBuf::writeToDevice(const char* buffer, std::streamsize length) return 0; _bytesWritten += length; _ptrOBuf->write(buffer, length); - _crc32.update(buffer, length); - return length; + _crc32.update(buffer, static_cast(length)); + return static_cast(length); } void ZipStreamBuf::close(Poco::UInt64& extraDataSize) { - extraDataSize = 0; + extraDataSize = 0; if (_ptrOBuf && _pHeader) { _ptrOBuf->flush();