Skip to content

Commit

Permalink
Suppress MSVC warnings about narrowing conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
TsudaKageyu committed Oct 30, 2016
1 parent ee7fa78 commit f5ce498
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions taglib/riff/rifffile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ unsigned int RIFF::File::riffSize() const

unsigned int RIFF::File::chunkCount() const
{
return d->chunks.size();
return static_cast<unsigned int>(d->chunks.size());
}

unsigned int RIFF::File::chunkDataSize(unsigned int i) const
Expand Down Expand Up @@ -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<int>(d->chunks.size()) - 1; i >= 0; --i) {
if(d->chunks[i].name == name)
removeChunk(i);
}
Expand Down
22 changes: 11 additions & 11 deletions taglib/toolkit/tbytevector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int findChar(

for(TIterator it = dataBegin + offset; it < dataEnd; it += byteAlign) {
if(*it == c)
return (it - dataBegin);
return static_cast<int>(it - dataBegin);
}

return -1;
Expand Down Expand Up @@ -105,7 +105,7 @@ int findVector(
++itPattern;

if(itPattern == patternEnd)
return (it - dataBegin);
return static_cast<int>(it - dataBegin);
}
}

Expand All @@ -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<T>(static_cast<unsigned char>(v[offset + i])) << shift;
sum |= static_cast<T>(static_cast<unsigned char>(v[static_cast<int>(offset + i)])) << shift;
}

return sum;
Expand Down Expand Up @@ -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<unsigned int>(::strlen(s)));
else
return ByteVector(s, length);
}
Expand Down Expand Up @@ -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<unsigned int>(::strlen(data))))
{
}

Expand Down Expand Up @@ -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<size_t>(-1)) // Use npos in taglib2.
if(offset == static_cast<unsigned int>(-1))
break;

detach();
Expand Down Expand Up @@ -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<unsigned int>(dst - (unsigned char*) output.data()));
return output;
}
return ByteVector();
Expand Down
9 changes: 4 additions & 5 deletions taglib/toolkit/tdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions taglib/toolkit/tfilestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>(readFile(d->file, aboutToOverwrite));
aboutToOverwrite.resize(bytesRead);
readPosition += bufferLength;

Expand Down Expand Up @@ -304,10 +304,10 @@ void FileStream::removeBlock(unsigned long start, unsigned long length)

ByteVector buffer(static_cast<unsigned int>(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<unsigned int>(readFile(d->file, buffer));
readPosition += bytesRead;

// Check to see if we just read the last block. We need to call clear()
Expand Down
2 changes: 1 addition & 1 deletion taglib/toolkit/tlist.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ List<T> &List<T>::clear()
template <class T>
unsigned int List<T>::size() const
{
return d->list.size();
return static_cast<unsigned int>(d->list.size());
}

template <class T>
Expand Down
2 changes: 1 addition & 1 deletion taglib/toolkit/tmap.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Map<Key, T> &Map<Key,T>::erase(const Key &key)
template <class Key, class T>
unsigned int Map<Key, T>::size() const
{
return d->map.size();
return static_cast<unsigned int>(d->map.size());
}

template <class Key, class T>
Expand Down
16 changes: 9 additions & 7 deletions taglib/toolkit/tstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(srcLength), dst, static_cast<int>(dstLength), NULL, NULL);

#else

Expand Down Expand Up @@ -86,7 +87,8 @@ namespace

#ifdef _WIN32

len = ::MultiByteToWideChar(CP_UTF8, 0, src, srcLength, dst, dstLength);
len = ::MultiByteToWideChar(
CP_UTF8, 0, src, static_cast<int>(srcLength), dst, static_cast<int>(dstLength));

#else

Expand Down Expand Up @@ -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<int>(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<int>(d->data.rfind(s.d->data, offset));
}

StringList String::split(const String &separator) const
Expand Down Expand Up @@ -479,7 +481,7 @@ String String::upper() const

unsigned int String::size() const
{
return d->data.size();
return static_cast<unsigned int>(d->data.size());
}

unsigned int String::length() const
Expand Down Expand Up @@ -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<unsigned int>(len));

return v;
}
Expand Down Expand Up @@ -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<unsigned int>(pos1), static_cast<unsigned int>(pos2 - pos1 + 1));
}

bool String::isLatin1() const
Expand Down

0 comments on commit f5ce498

Please sign in to comment.