From f5ce49818286324305c9a6842d81ecc0ff1913bb Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 30 Oct 2016 23:51:35 +0900 Subject: [PATCH] Suppress MSVC warnings about narrowing conversions. --- taglib/riff/rifffile.cpp | 4 ++-- taglib/toolkit/tbytevector.cpp | 22 +++++++++++----------- taglib/toolkit/tdebug.cpp | 9 ++++----- taglib/toolkit/tfilestream.cpp | 6 +++--- taglib/toolkit/tlist.tcc | 2 +- taglib/toolkit/tmap.tcc | 2 +- taglib/toolkit/tstring.cpp | 16 +++++++++------- 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index f874f7ad..51c9af41 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -95,7 +95,7 @@ unsigned int RIFF::File::riffSize() const unsigned int RIFF::File::chunkCount() const { - return d->chunks.size(); + return static_cast(d->chunks.size()); } unsigned int RIFF::File::chunkDataSize(unsigned int i) const @@ -269,7 +269,7 @@ void RIFF::File::removeChunk(unsigned int i) void RIFF::File::removeChunk(const ByteVector &name) { - for(int i = d->chunks.size() - 1; i >= 0; --i) { + for(int i = static_cast(d->chunks.size()) - 1; i >= 0; --i) { if(d->chunks[i].name == name) removeChunk(i); } diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 6494a448..a2258bc5 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -63,7 +63,7 @@ int findChar( for(TIterator it = dataBegin + offset; it < dataEnd; it += byteAlign) { if(*it == c) - return (it - dataBegin); + return static_cast(it - dataBegin); } return -1; @@ -105,7 +105,7 @@ int findVector( ++itPattern; if(itPattern == patternEnd) - return (it - dataBegin); + return static_cast(it - dataBegin); } } @@ -125,7 +125,7 @@ T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignifica T sum = 0; for(size_t i = 0; i < length; i++) { const size_t shift = (mostSignificantByteFirst ? length - 1 - i : i) * 8; - sum |= static_cast(static_cast(v[offset + i])) << shift; + sum |= static_cast(static_cast(v[static_cast(offset + i)])) << shift; } return sum; @@ -300,7 +300,7 @@ ByteVector ByteVector::null; ByteVector ByteVector::fromCString(const char *s, unsigned int length) { if(length == 0xffffffff) - return ByteVector(s, ::strlen(s)); + return ByteVector(s, static_cast(::strlen(s))); else return ByteVector(s, length); } @@ -375,7 +375,7 @@ ByteVector::ByteVector(const char *data, unsigned int length) : } ByteVector::ByteVector(const char *data) : - d(new ByteVectorPrivate(data, ::strlen(data))) + d(new ByteVectorPrivate(data, static_cast(::strlen(data)))) { } @@ -493,14 +493,14 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit if(pattern.size() == 1 && with.size() == 1) return replace(pattern[0], with[0]); - const size_t withSize = with.size(); - const size_t patternSize = pattern.size(); - const ptrdiff_t diff = withSize - patternSize; + const unsigned int withSize = with.size(); + const unsigned int patternSize = pattern.size(); + const int diff = withSize - patternSize; - size_t offset = 0; + unsigned int offset = 0; while (true) { offset = find(pattern, offset); - if(offset == static_cast(-1)) // Use npos in taglib2. + if(offset == static_cast(-1)) break; detach(); @@ -963,7 +963,7 @@ ByteVector ByteVector::fromBase64(const ByteVector & input) // Only return output if we processed all bytes if(len == 0) { - output.resize(dst - (unsigned char*) output.data()); + output.resize(static_cast(dst - (unsigned char*) output.data())); return output; } return ByteVector(); diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index d630791c..b2efc4cb 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -50,11 +50,10 @@ namespace TagLib void debugData(const ByteVector &v) { - for(size_t i = 0; i < v.size(); ++i) - { - std::string bits = std::bitset<8>(v[i]).to_string(); - String msg = Utils::formatString( - "*** [%d] - char '%c' - int %d, 0x%02x, 0b%s\n", + for(unsigned int i = 0; i < v.size(); ++i) { + const std::string bits = std::bitset<8>(v[i]).to_string(); + const String msg = Utils::formatString( + "*** [%u] - char '%c' - int %d, 0x%02x, 0b%s\n", i, v[i], v[i], v[i], bits.c_str()); debugListener->printMessage(msg); diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 478f09a0..4f522a62 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -261,7 +261,7 @@ void FileStream::insert(const ByteVector &data, unsigned long start, unsigned lo // to overwrite. Appropriately increment the readPosition. seek(readPosition); - const size_t bytesRead = readFile(d->file, aboutToOverwrite); + const unsigned int bytesRead = static_cast(readFile(d->file, aboutToOverwrite)); aboutToOverwrite.resize(bytesRead); readPosition += bufferLength; @@ -304,10 +304,10 @@ void FileStream::removeBlock(unsigned long start, unsigned long length) ByteVector buffer(static_cast(bufferLength)); - for(size_t bytesRead = -1; bytesRead != 0;) + for(unsigned int bytesRead = -1; bytesRead != 0;) { seek(readPosition); - bytesRead = readFile(d->file, buffer); + bytesRead = static_cast(readFile(d->file, buffer)); readPosition += bytesRead; // Check to see if we just read the last block. We need to call clear() diff --git a/taglib/toolkit/tlist.tcc b/taglib/toolkit/tlist.tcc index bf8b0007..a55eb620 100644 --- a/taglib/toolkit/tlist.tcc +++ b/taglib/toolkit/tlist.tcc @@ -196,7 +196,7 @@ List &List::clear() template unsigned int List::size() const { - return d->list.size(); + return static_cast(d->list.size()); } template diff --git a/taglib/toolkit/tmap.tcc b/taglib/toolkit/tmap.tcc index 68f0d311..c1227f3a 100644 --- a/taglib/toolkit/tmap.tcc +++ b/taglib/toolkit/tmap.tcc @@ -152,7 +152,7 @@ Map &Map::erase(const Key &key) template unsigned int Map::size() const { - return d->map.size(); + return static_cast(d->map.size()); } template diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 83287905..a1891a45 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -54,7 +54,8 @@ namespace #ifdef _WIN32 - len = ::WideCharToMultiByte(CP_UTF8, 0, src, srcLength, dst, dstLength, NULL, NULL); + len = ::WideCharToMultiByte( + CP_UTF8, 0, src, static_cast(srcLength), dst, static_cast(dstLength), NULL, NULL); #else @@ -86,7 +87,8 @@ namespace #ifdef _WIN32 - len = ::MultiByteToWideChar(CP_UTF8, 0, src, srcLength, dst, dstLength); + len = ::MultiByteToWideChar( + CP_UTF8, 0, src, static_cast(srcLength), dst, static_cast(dstLength)); #else @@ -410,12 +412,12 @@ String::ConstIterator String::end() const int String::find(const String &s, int offset) const { - return d->data.find(s.d->data, offset); + return static_cast(d->data.find(s.d->data, offset)); } int String::rfind(const String &s, int offset) const { - return d->data.rfind(s.d->data, offset); + return static_cast(d->data.rfind(s.d->data, offset)); } StringList String::split(const String &separator) const @@ -479,7 +481,7 @@ String String::upper() const unsigned int String::size() const { - return d->data.size(); + return static_cast(d->data.size()); } unsigned int String::length() const @@ -518,7 +520,7 @@ ByteVector String::data(Type t) const const size_t len = UTF16toUTF8( d->data.c_str(), d->data.size(), v.data(), v.size()); - v.resize(len); + v.resize(static_cast(len)); return v; } @@ -604,7 +606,7 @@ String String::stripWhiteSpace() const return String(); const size_t pos2 = d->data.find_last_not_of(WhiteSpaceChars); - return substr(pos1, pos2 - pos1 + 1); + return substr(static_cast(pos1), static_cast(pos2 - pos1 + 1)); } bool String::isLatin1() const -- 2.40.0