From df3f5e442d1a1fed2b37b27774af77a4dd0f71a4 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 17 Apr 2014 11:57:48 -0700 Subject: [PATCH] Fix VS2013 warnings about integer conversions --- beast/HeapBlock.h | 4 ++-- beast/container/impl/spookyv2.cpp | 3 ++- beast/crypto/tests/BinaryEncoding.cpp | 12 +++++++----- beast/threads/ServiceQueue.h | 2 +- beast/threads/tests/ServiceQueue.cpp | 10 +++++----- modules/beast_asio/http/HTTPClientType.cpp | 2 +- modules/beast_asio/http/HTTPHeaders.cpp | 4 ++-- modules/beast_asio/http/HTTPHeaders.h | 4 ++-- modules/beast_core/containers/ArrayAllocationBase.h | 4 ++-- modules/beast_core/memory/MemoryBlock.cpp | 4 ++-- modules/beast_sqdb/api/blob.h | 6 +++--- modules/beast_sqdb/source/blob.cpp | 6 +++--- modules/beast_sqdb/source/use_type.cpp | 4 ++-- 13 files changed, 34 insertions(+), 31 deletions(-) diff --git a/beast/HeapBlock.h b/beast/HeapBlock.h index aff4006e6..9fdea3e98 100644 --- a/beast/HeapBlock.h +++ b/beast/HeapBlock.h @@ -294,7 +294,7 @@ public: The semantics of this method are the same as malloc() and calloc(), but it uses realloc() to keep as much of the existing data as possible. */ - void realloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) + void reallocate (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { data = static_cast (data == nullptr ? std::malloc (newNumElements * elementSize) : std::realloc (data, newNumElements * elementSize)); @@ -304,7 +304,7 @@ public: /** Frees any currently-allocated data. This will free the data and reset this object to be a null pointer. */ - void free() + void free_up() { std::free (data); data = nullptr; diff --git a/beast/container/impl/spookyv2.cpp b/beast/container/impl/spookyv2.cpp index 9b7721c38..b6d444888 100644 --- a/beast/container/impl/spookyv2.cpp +++ b/beast/container/impl/spookyv2.cpp @@ -183,7 +183,8 @@ void SpookyHash::Hash128( remainder = (length - ((const uint8 *)end-(const uint8 *)message)); memcpy(buf, end, remainder); memset(((uint8 *)buf)+remainder, 0, sc_blockSize-remainder); - ((uint8 *)buf)[sc_blockSize-1] = remainder; + ((uint8 *)buf)[sc_blockSize-1] = + static_cast(remainder); // do some final mixing End(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11); diff --git a/beast/crypto/tests/BinaryEncoding.cpp b/beast/crypto/tests/BinaryEncoding.cpp index 5be99858a..eaf5a7104 100644 --- a/beast/crypto/tests/BinaryEncoding.cpp +++ b/beast/crypto/tests/BinaryEncoding.cpp @@ -114,10 +114,11 @@ public: } /** Build the inverse mapping table from characters to digits. */ - static std::vector invert (std::string const& alphabet, std::size_t radix) + static std::vector + invert (std::string const& alphabet, int radix) { std::vector table (256, -1); - for (std::size_t i (0); i < radix; ++i) + for (int i (0); i < radix; ++i) table [alphabet [i]] = i; return table; } @@ -183,11 +184,12 @@ public: } /** Build the inverse mapping table from characters to digits. */ - static std::vector invert (std::string const& alphabet, std::size_t radix) + static std::vector + invert (std::string const& alphabet, int radix) { std::vector table (256, -1); - for (std::size_t i (0); i < radix; ++i) - table [alphabet [i]] = i; + for (int i (0); i < radix; ++i) + table [alphabet [i]] = int(i); return table; } }; diff --git a/beast/threads/ServiceQueue.h b/beast/threads/ServiceQueue.h index c001865c6..eac6d6cfb 100644 --- a/beast/threads/ServiceQueue.h +++ b/beast/threads/ServiceQueue.h @@ -430,7 +430,7 @@ private: public: typedef Allocator allocator_type; // for std::uses_allocator<> - explicit ServiceQueueType (int expectedConcurrency = 1, + explicit ServiceQueueType (std::size_t expectedConcurrency = 1, Allocator alloc = Allocator()) : m_alloc (alloc) { diff --git a/beast/threads/tests/ServiceQueue.cpp b/beast/threads/tests/ServiceQueue.cpp index f90aa649f..9893aa44b 100644 --- a/beast/threads/tests/ServiceQueue.cpp +++ b/beast/threads/tests/ServiceQueue.cpp @@ -128,7 +128,7 @@ public: //-------------------------------------------------------------------------- template - void testThreads (std::size_t nConsumers, std::size_t nProducers) + void testThreads (int nConsumers, int nProducers) { std::stringstream ss; ss << @@ -147,11 +147,11 @@ public: Random r; - for (std::size_t i = 0; i < nConsumers; ++i) + for (int i = 0; i < nConsumers; ++i) consumers.emplace_back (new Consumer (i + 1, r.nextInt64(), service)); - for (std::size_t i = 0; i < nProducers; ++i) + for (int i = 0; i < nProducers; ++i) producers.emplace_back (new Producer (i + 1, r.nextInt64(), service)); @@ -258,7 +258,7 @@ public: static std::size_t const totalCalls = 10000; - void testThreads (std::size_t n) + void testThreads (int n) { std::stringstream ss; ss << n << " threads"; @@ -270,7 +270,7 @@ public: ServiceQueue service (n); std::vector > threads; threads.reserve (n); - for (std::size_t i = 0; i < n; ++i) + for (int i = 0; i < n; ++i) threads.emplace_back (new ServiceThread (i + 1, r.nextInt64(), service)); for (std::size_t i = n * callsPerThread; i; --i) diff --git a/modules/beast_asio/http/HTTPClientType.cpp b/modules/beast_asio/http/HTTPClientType.cpp index 454976bf5..8dc68feec 100644 --- a/modules/beast_asio/http/HTTPClientType.cpp +++ b/modules/beast_asio/http/HTTPClientType.cpp @@ -598,7 +598,7 @@ public: void print (HTTPMessage const& m) { - for (std::size_t i = 0; i < m.headers().size(); ++i) + for (int i = 0; i < m.headers().size(); ++i) { HTTPField const f (m.headers()[i]); std::stringstream ss; diff --git a/modules/beast_asio/http/HTTPHeaders.cpp b/modules/beast_asio/http/HTTPHeaders.cpp index 69aff96ac..18e7cbb79 100644 --- a/modules/beast_asio/http/HTTPHeaders.cpp +++ b/modules/beast_asio/http/HTTPHeaders.cpp @@ -54,13 +54,13 @@ std::size_t HTTPHeaders::size () const return m_fields.size (); } -HTTPField HTTPHeaders::at (std::size_t index) const +HTTPField HTTPHeaders::at (int index) const { return HTTPField (m_fields.getAllKeys () [index], m_fields.getAllValues () [index]); } -HTTPField HTTPHeaders::operator[] (std::size_t index) const +HTTPField HTTPHeaders::operator[] (int index) const { return at (index); } diff --git a/modules/beast_asio/http/HTTPHeaders.h b/modules/beast_asio/http/HTTPHeaders.h index 7974d2a26..12688f714 100644 --- a/modules/beast_asio/http/HTTPHeaders.h +++ b/modules/beast_asio/http/HTTPHeaders.h @@ -51,8 +51,8 @@ public: /** Random access to fields by index. */ /** @{ */ - HTTPField at (std::size_t index) const; - HTTPField operator[] (std::size_t index) const; + HTTPField at (int index) const; + HTTPField operator[] (int index) const; /** @} */ /** Associative access to fields by name. diff --git a/modules/beast_core/containers/ArrayAllocationBase.h b/modules/beast_core/containers/ArrayAllocationBase.h index 72c2edd69..6fd4358ab 100644 --- a/modules/beast_core/containers/ArrayAllocationBase.h +++ b/modules/beast_core/containers/ArrayAllocationBase.h @@ -85,9 +85,9 @@ public: if (numAllocated != numElements) { if (numElements > 0) - elements.realloc ((size_t) numElements); + elements.reallocate ((size_t) numElements); else - elements.free(); + elements.free_up(); numAllocated = numElements; } diff --git a/modules/beast_core/memory/MemoryBlock.cpp b/modules/beast_core/memory/MemoryBlock.cpp index 0eccc652a..0c85889f7 100644 --- a/modules/beast_core/memory/MemoryBlock.cpp +++ b/modules/beast_core/memory/MemoryBlock.cpp @@ -125,14 +125,14 @@ void MemoryBlock::setSize (const size_t newSize, const bool initialiseToZero) { if (newSize <= 0) { - data.free(); + data.free_up(); size = 0; } else { if (data != nullptr) { - data.realloc (newSize); + data.reallocate (newSize); if (initialiseToZero && (newSize > size)) zeromem (data + size, newSize - size); diff --git a/modules/beast_sqdb/api/blob.h b/modules/beast_sqdb/api/blob.h index 6f3c16893..16bf28f5f 100644 --- a/modules/beast_sqdb/api/blob.h +++ b/modules/beast_sqdb/api/blob.h @@ -76,9 +76,9 @@ public: rowid id, bool readAndWrite = false) noexcept; - std::size_t get_len(); - Error read(std::size_t offset, void* buf, std::size_t toRead); - Error write(std::size_t offset, void const* buf, std::size_t toWrite); + int get_len(); + Error read(int offset, void* buf, int toRead); + Error write(int offset, void const* buf, int toWrite); void close(); private: diff --git a/modules/beast_sqdb/source/blob.cpp b/modules/beast_sqdb/source/blob.cpp index 39681c2bc..e8fb3e359 100644 --- a/modules/beast_sqdb/source/blob.cpp +++ b/modules/beast_sqdb/source/blob.cpp @@ -91,18 +91,18 @@ Error blob::select(session& s, return detail::sqliteError(__FILE__, __LINE__, result); } -std::size_t blob::get_len() +int blob::get_len() { return sqlite3_blob_bytes(m_blob); } -Error blob::read(std::size_t offset, void* buf, std::size_t toRead) +Error blob::read(int offset, void* buf, int toRead) { return detail::sqliteError(__FILE__, __LINE__, sqlite3_blob_read(m_blob, static_cast(buf), toRead, offset)); } -Error blob::write(std::size_t offset, void const* buf, std::size_t toWrite) +Error blob::write(int offset, void const* buf, int toWrite) { return detail::sqliteError(__FILE__, __LINE__, sqlite3_blob_write(m_blob, buf, toWrite, offset)); diff --git a/modules/beast_sqdb/source/use_type.cpp b/modules/beast_sqdb/source/use_type.cpp index a9ca37314..d9146a787 100644 --- a/modules/beast_sqdb/source/use_type.cpp +++ b/modules/beast_sqdb/source/use_type.cpp @@ -177,7 +177,7 @@ void standard_use_type::do_use() result = sqlite3_bind_text(m_st->m_stmt, m_iParam, s.c_str(), - s.size() * sizeof(s[0]), + int(s.size() * sizeof(s[0])), SQLITE_STATIC); } break; @@ -188,7 +188,7 @@ void standard_use_type::do_use() result = sqlite3_bind_text16(m_st->m_stmt, m_iParam, s.c_str(), - s.size() * sizeof(s[0]), + int(s.size() * sizeof(s[0])), SQLITE_STATIC); } break;