From aa444bcfb9123cf0d11316905365246c2d3f5cd0 Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Thu, 24 Oct 2013 04:40:21 +0200 Subject: [PATCH] Fix warnings with older Boost version Apparently boost::size(array) used to be signed :( --- src/cli/debug.cpp | 2 +- src/crypto/checksum.cpp | 8 ++++---- src/crypto/iteratedhash.hpp | 2 +- src/loader/offsets.cpp | 2 +- src/setup/version.cpp | 9 +++++---- src/setup/windows.cpp | 4 ++-- src/stream/chunk.cpp | 2 +- src/util/enum.hpp | 2 +- src/util/load.hpp | 2 +- src/util/output.hpp | 2 +- 10 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/cli/debug.cpp b/src/cli/debug.cpp index 2eef5c4..ec7feff 100644 --- a/src/cli/debug.cpp +++ b/src/cli/debug.cpp @@ -524,7 +524,7 @@ static const char * magic_numbers[][2] = { static const char * guess_extension(const std::string & data) { - for(size_t i = 0; i < boost::size(magic_numbers); i++) { + for(size_t i = 0; i < size_t(boost::size(magic_numbers)); i++) { size_t n = strlen(magic_numbers[i][0]); diff --git a/src/crypto/checksum.cpp b/src/crypto/checksum.cpp index c9848b1..928fad1 100644 --- a/src/crypto/checksum.cpp +++ b/src/crypto/checksum.cpp @@ -38,8 +38,8 @@ bool checksum::operator==(const checksum & o) const { switch(type) { case Adler32: return (adler32 == o.adler32); case CRC32: return (crc32 == o.crc32); - case MD5: return !memcmp(md5, o.md5, boost::size(md5)); - case SHA1: return !memcmp(sha1, o.sha1, boost::size(sha1)); + case MD5: return !memcmp(md5, o.md5, sizeof(md5)); + case SHA1: return !memcmp(sha1, o.sha1, sizeof(sha1)); default: return false; }; } @@ -69,13 +69,13 @@ std::ostream & operator<<(std::ostream & os, const crypto::checksum & checksum) break; } case crypto::MD5: { - for(size_t i = 0; i < boost::size(checksum.md5); i++) { + for(size_t i = 0; i < size_t(boost::size(checksum.md5)); i++) { os << std::setfill('0') << std::hex << std::setw(2) << int(boost::uint8_t(checksum.md5[i])); } break; } case crypto::SHA1: { - for(size_t i = 0; i < boost::size(checksum.sha1); i++) { + for(size_t i = 0; i < size_t(boost::size(checksum.sha1)); i++) { os << std::setfill('0') << std::hex << std::setw(2) << int(boost::uint8_t(checksum.sha1[i])); } break; diff --git a/src/crypto/iteratedhash.hpp b/src/crypto/iteratedhash.hpp index 43c5c38..a638df4 100644 --- a/src/crypto/iteratedhash.hpp +++ b/src/crypto/iteratedhash.hpp @@ -127,7 +127,7 @@ size_t iterated_hash::hash(const char * input, size_t length) { do { hash_word buffer[block_size / sizeof(hash_word)]; - byte_order::load(input, buffer, boost::size(buffer)); + byte_order::load(input, buffer, size_t(boost::size(buffer))); transform::transform(state, buffer); diff --git a/src/loader/offsets.cpp b/src/loader/offsets.cpp index 6647129..158737e 100644 --- a/src/loader/offsets.cpp +++ b/src/loader/offsets.cpp @@ -108,7 +108,7 @@ bool offsets::load_offsets_at(std::istream & is, boost::uint32_t pos) { } setup::version_constant version = 0; - for(size_t i = 0; i < boost::size(known_setup_loader_versions); i++) { + for(size_t i = 0; i < size_t(boost::size(known_setup_loader_versions)); i++) { BOOST_STATIC_ASSERT(sizeof(known_setup_loader_versions[i].magic) == sizeof(magic)); if(!memcmp(magic, known_setup_loader_versions[i].magic, sizeof(magic))) { version = known_setup_loader_versions[i].version; diff --git a/src/setup/version.cpp b/src/setup/version.cpp index ecd59f9..2792189 100644 --- a/src/setup/version.cpp +++ b/src/setup/version.cpp @@ -184,7 +184,7 @@ void version::load(std::istream & is) { if(legacy_version[0] == 'i' && legacy_version[sizeof(legacy_version) - 1] == '\x1a') { - for(size_t i = 0; i < boost::size(legacy_versions); i++) { + for(size_t i = 0; i < size_t(boost::size(legacy_versions)); i++) { if(!memcmp(legacy_version, legacy_versions[i].name, sizeof(legacy_version))) { value = legacy_versions[i].version; bits = legacy_versions[i].bits; @@ -196,7 +196,7 @@ void version::load(std::istream & is) { } debug("unknown legacy version: \"" - << std::string(legacy_version, boost::size(legacy_version)) << '"'); + << std::string(legacy_version, sizeof(legacy_version)) << '"'); if(legacy_version[0] != 'i' || legacy_version[2] != '.' || legacy_version[4] != '.' || legacy_version[7] != '-' || legacy_version[8] != '-') { @@ -211,7 +211,7 @@ void version::load(std::istream & is) { throw version_error(); } - std::string version_str(legacy_version, legacy_version + boost::size(legacy_version)); + std::string version_str(legacy_version, sizeof(legacy_version)); try { unsigned a = to_unsigned(version_str.data() + 1, 1); @@ -229,12 +229,13 @@ void version::load(std::istream & is) { } stored_version version; + BOOST_STATIC_ASSERT(sizeof(legacy_version) <= sizeof(version)); memcpy(version, legacy_version, sizeof(legacy_version)); is.read(version + sizeof(legacy_version), std::streamsize(sizeof(version) - sizeof(legacy_version))); - for(size_t i = 0; i < boost::size(versions); i++) { + for(size_t i = 0; i < size_t(boost::size(versions)); i++) { if(!memcmp(version, versions[i].name, sizeof(version))) { value = versions[i].version; bits = 32; diff --git a/src/setup/windows.cpp b/src/setup/windows.cpp index fc962d8..dbf7b55 100644 --- a/src/setup/windows.cpp +++ b/src/setup/windows.cpp @@ -103,9 +103,9 @@ const char * get_version_name(const windows_version::data & version, bool nt = f windows_version_name * names; size_t count; if(nt) { - names = windows_nt_version_names, count = boost::size(windows_nt_version_names); + names = windows_nt_version_names, count = size_t(boost::size(windows_nt_version_names)); } else { - names = windows_version_names, count = boost::size(windows_version_names); + names = windows_version_names, count = size_t(boost::size(windows_version_names)); } for(size_t i = 0; i < count; i++) { diff --git a/src/stream/chunk.cpp b/src/stream/chunk.cpp index eadafc1..05b89aa 100644 --- a/src/stream/chunk.cpp +++ b/src/stream/chunk.cpp @@ -69,7 +69,7 @@ chunk_reader::pointer chunk_reader::get(slice_reader & base, const chunk & chunk } char magic[sizeof(chunk_id)]; - if(base.read(magic, 4) != 4 || memcmp(magic, chunk_id, boost::size(chunk_id))) { + if(base.read(magic, 4) != 4 || memcmp(magic, chunk_id, sizeof(chunk_id))) { throw chunk_error("bad chunk magic"); } diff --git a/src/util/enum.hpp b/src/util/enum.hpp index 4b96b78..0c10c53 100644 --- a/src/util/enum.hpp +++ b/src/util/enum.hpp @@ -66,7 +66,7 @@ struct enum_names { const char * enum_names::type>::name = (Name); \ const char * enum_names::type>::names[] = { __VA_ARGS__ }; \ const size_t enum_names::type>::count \ - = boost::size(enum_names::type>::names); + = size_t(boost::size(enum_names::type>::names)); #define USE_ENUM_NAMES(Enum) \ (void)enum_names::type>::count; \ diff --git a/src/util/load.hpp b/src/util/load.hpp index 6937504..5854c02 100644 --- a/src/util/load.hpp +++ b/src/util/load.hpp @@ -191,7 +191,7 @@ template void discard(T & is, boost::uint64_t bytes) { char buf[1024]; while(bytes) { - std::streamsize n = std::streamsize(std::min(bytes, boost::size(buf))); + std::streamsize n = std::streamsize(std::min(bytes, sizeof(buf))); is.read(buf, n); bytes -= boost::uint64_t(n); } diff --git a/src/util/output.hpp b/src/util/output.hpp index 4cbf611..29bc604 100644 --- a/src/util/output.hpp +++ b/src/util/output.hpp @@ -185,7 +185,7 @@ std::ostream & operator<<(std::ostream & os, const print_bytes & s) { size_t i = 0; - while(whole > 1024 && i < boost::size(byte_size_units) - 1) { + while(whole > 1024 && i < size_t(boost::size(byte_size_units)) - 1) { frac = whole % 1024, whole /= 1024;