From 75159614fcef84f8e573c5482481c8816981ff76 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 21 Dec 2015 15:17:59 +0900 Subject: [PATCH] Silence MSVC warnings concerning narrowing conversions. --- taglib/asf/asfutils.h | 4 ++-- taglib/fileref.cpp | 4 ++-- taglib/mod/modfile.cpp | 6 +++--- taglib/mp4/mp4tag.cpp | 4 ++-- taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp | 4 ++-- taglib/mpeg/id3v2/id3v2framefactory.cpp | 2 +- taglib/ogg/xiphcomment.cpp | 4 ++-- taglib/riff/rifffile.cpp | 4 ++-- taglib/toolkit/tstring.cpp | 6 ++++-- tests/test_riff.cpp | 2 +- 10 files changed, 21 insertions(+), 19 deletions(-) diff --git a/taglib/asf/asfutils.h b/taglib/asf/asfutils.h index 88396a55..9cc51caa 100644 --- a/taglib/asf/asfutils.h +++ b/taglib/asf/asfutils.h @@ -71,8 +71,8 @@ namespace TagLib inline String readString(File *file, int length) { ByteVector data = file->readBlock(length); - unsigned int size = data.size(); - while (size >= 2) { + size_t size = data.size(); + while(size >= 2) { if(data[size - 1] != '\0' || data[size - 2] != '\0') { break; } diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 19e44dcf..9d33c83d 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -125,8 +125,8 @@ namespace #endif String ext; - const int pos = s.rfind("."); - if(pos != -1) + const size_t pos = s.rfind("."); + if(pos != String::npos()) ext = s.substr(pos + 1).upper(); // If this list is updated, the method defaultFileExtensions() should also be diff --git a/taglib/mod/modfile.cpp b/taglib/mod/modfile.cpp index 1aaf6d74..fd89b296 100644 --- a/taglib/mod/modfile.cpp +++ b/taglib/mod/modfile.cpp @@ -82,13 +82,13 @@ bool Mod::File::save() seek(0); writeString(d->tag.title(), 20); StringList lines = d->tag.comment().split("\n"); - unsigned int n = std::min(lines.size(), d->properties.instrumentCount()); - for(unsigned int i = 0; i < n; ++ i) { + size_t n = std::min(lines.size(), d->properties.instrumentCount()); + for(size_t i = 0; i < n; ++ i) { writeString(lines[i], 22); seek(8, Current); } - for(unsigned int i = n; i < d->properties.instrumentCount(); ++ i) { + for(size_t i = n; i < d->properties.instrumentCount(); ++ i) { writeString(String(), 22); seek(8, Current); } diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 52b7c73b..7d2629ac 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -628,8 +628,8 @@ MP4::Tag::saveNew(ByteVector data) long long offset = path.back()->offset + 8; d->file->insert(data, offset, 0); - updateParents(path, data.size()); - updateOffsets(data.size(), offset); + updateParents(path, static_cast(data.size())); + updateOffsets(static_cast(data.size()), offset); // Insert the newly created atoms into the tree to keep it up-to-date. diff --git a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp index 76cef76a..20298912 100644 --- a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp +++ b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp @@ -123,7 +123,7 @@ bool TableOfContentsFrame::isOrdered() const unsigned int TableOfContentsFrame::entryCount() const { - return d->childElements.size(); + return static_cast(d->childElements.size()); } ByteVectorList TableOfContentsFrame::childElements() const @@ -261,7 +261,7 @@ TableOfContentsFrame *TableOfContentsFrame::findTopLevel(const ID3v2::Tag *tag) void TableOfContentsFrame::parseFields(const ByteVector &data) { - unsigned int size = data.size(); + size_t size = data.size(); if(size < 6) { debug("A CTOC frame must contain at least 6 bytes (1 byte element ID terminated by " "null, 1 byte flags, 1 byte entry count and 1 byte child element ID terminated " diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index 04a9b7fc..e5985a7f 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -63,7 +63,7 @@ namespace for(StringList::ConstIterator it = fields.begin(); it != fields.end(); ++it) { String s = *it; - int end = s.find(")"); + size_t end = s.find(")"); if(s.startsWith("(") && end > 0) { // "(12)Genre" diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index a3ee83e8..0bd8e28d 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -211,14 +211,14 @@ bool Ogg::XiphComment::isEmpty() const unsigned int Ogg::XiphComment::fieldCount() const { - unsigned int count = 0; + size_t count = 0; for(FieldConstIterator it = d->fieldListMap.begin(); it != d->fieldListMap.end(); ++it) count += (*it).second.size(); count += d->pictureList.size(); - return count; + return static_cast(count); } const Ogg::FieldListMap &Ogg::XiphComment::fieldListMap() const diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index 51a8a5ab..019d2fac 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -224,7 +224,7 @@ void RIFF::File::removeChunk(unsigned int i) std::vector::iterator it = d->chunks.begin(); std::advance(it, i); - const unsigned int removeSize = it->size + it->padding + 8; + const size_t removeSize = it->size + it->padding + 8; removeBlock(it->offset - 8, removeSize); it = d->chunks.erase(it); @@ -234,7 +234,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/tstring.cpp b/taglib/toolkit/tstring.cpp index d3637e92..cdb12b06 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -58,7 +58,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 @@ -91,7 +92,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 diff --git a/tests/test_riff.cpp b/tests/test_riff.cpp index b2681f71..193f32ab 100644 --- a/tests/test_riff.cpp +++ b/tests/test_riff.cpp @@ -14,7 +14,7 @@ class PublicRIFF : public RIFF::File public: PublicRIFF(FileName file) : RIFF::File(file, BigEndian) {}; unsigned int riffSize() { return RIFF::File::riffSize(); }; - unsigned int chunkCount() { return RIFF::File::chunkCount(); }; + size_t chunkCount() { return RIFF::File::chunkCount(); }; long long chunkOffset(unsigned int i) { return RIFF::File::chunkOffset(i); }; unsigned int chunkPadding(unsigned int i) { return RIFF::File::chunkPadding(i); }; unsigned int chunkDataSize(unsigned int i) { return RIFF::File::chunkDataSize(i); };