From 70044534aadd0b1a4cad1452cf9edaccab1a9157 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Wed, 1 May 2013 22:14:05 +0900 Subject: [PATCH] Fixed some MSVC specific warnings --- taglib/ebml/ebmlelement.cpp | 29 +++++++++++----------- taglib/ebml/matroska/ebmlmatroskaaudio.cpp | 6 ++--- taglib/mpeg/mpegfile.cpp | 3 ++- taglib/toolkit/tfilestream.cpp | 4 +-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/taglib/ebml/ebmlelement.cpp b/taglib/ebml/ebmlelement.cpp index 4eb0579b..930c1a4b 100644 --- a/taglib/ebml/ebmlelement.cpp +++ b/taglib/ebml/ebmlelement.cpp @@ -112,8 +112,8 @@ public: } // Calculate the minimal length of the variable length integer - uint byteSize = vint.size(); - for(uint i = 0; byteSize > 0 && vint[i] == 0; ++i) + size_t byteSize = vint.size(); + for(size_t i = 0; byteSize > 0 && vint[i] == 0; ++i) --byteSize; if(!addOne) @@ -125,7 +125,7 @@ public: if(number >= (firstByte << (8 * (byteSize - 1))) && byteSize < vint.size()) ++byteSize; // Add the one at the correct position - uint firstBytePosition = vint.size() - byteSize; + size_t firstBytePosition = vint.size() - byteSize; vint[firstBytePosition] |= (1 << firstBytePosition); return ByteVector(vint.data() + firstBytePosition, byteSize); } @@ -207,7 +207,7 @@ public: ByteVector content(createVInt(id, false).append(createVInt(size, true, false))); data = position + content.size(); // space for children - content.resize(data - position + size); + content.resize(static_cast(data - position + size)); Element *freeSpace; if (!(freeSpace = searchVoid(content.size()))) { @@ -218,7 +218,7 @@ public: current->d->size += content.size(); // Create new header and write it. ByteVector parentHeader(createVInt(current->d->id, false).append(createVInt(current->d->size, true, false))); - uint oldHeaderSize = current->d->data - current->d->position; + size_t oldHeaderSize = static_cast(current->d->data - current->d->position); if(oldHeaderSize < parentHeader.size()) { ByteVector secondHeader(createVInt(current->d->id, false).append(createVInt(current->d->size))); if(oldHeaderSize == secondHeader.size()) { @@ -258,7 +258,8 @@ public: freeSpace->d->size = newSize; freeSpace->d->data = freeSpace->d->position + newVoid.size(); // Write to file - document->writeBlock(newVoid.resize(newVoid.size() + newSize).append(content)); + document->writeBlock( + newVoid.resize(static_cast(newVoid.size() + newSize)).append(content)); } } } @@ -315,7 +316,7 @@ EBML::Element *EBML::Element::getParent() ByteVector EBML::Element::getAsBinary() { d->document->seek(d->data); - return d->document->readBlock(d->size); + return d->document->readBlock(static_cast(d->size)); } String EBML::Element::getAsString() @@ -341,16 +342,16 @@ long double EBML::Element::getAsFloat() { // Very dirty implementation! ByteVector bin = getAsBinary(); - uint size = bin.size(); - ulli sum = 0.0L; + size_t size = bin.size(); + ulli sum = 0; // For 0 byte floats and any float that is not defined in the ebml spec. if (size != 4 && size != 8 /*&& size() != 10*/) // XXX: Currently no support for 10 bit floats. - return sum; + return static_cast(sum); // From toNumber; Might not be portable, since it requires IEEE floats. - uint last = size - 1; - for(uint i = 0; i <= last; i++) + size_t last = size - 1; + for(size_t i = 0; i <= last; i++) sum |= (ulli) uchar(bin[i]) << ((last - i) * 8); if (size == 4) { @@ -433,7 +434,7 @@ bool EBML::Element::removeChild(Element *element, bool useVoid) return false; if(!useVoid || !element->d->makeVoid()) { - d->document->removeBlock(element->d->position, element->d->size); + d->document->removeBlock(element->d->position, static_cast(element->d->size)); // Update parents for(Element* current = this; current; current = current->d->parent) current->d->size -= element->d->size; @@ -449,7 +450,7 @@ bool EBML::Element::removeChild(Element *element, bool useVoid) void EBML::Element::setAsBinary(const ByteVector &binary) { // Maybe: Search for void element after this one - d->document->insert(binary, d->data, d->size); + d->document->insert(binary, d->data, static_cast(d->size)); } void EBML::Element::setAsString(const String &string) diff --git a/taglib/ebml/matroska/ebmlmatroskaaudio.cpp b/taglib/ebml/matroska/ebmlmatroskaaudio.cpp index 3ae9734d..8f3cdd00 100644 --- a/taglib/ebml/matroska/ebmlmatroskaaudio.cpp +++ b/taglib/ebml/matroska/ebmlmatroskaaudio.cpp @@ -46,7 +46,7 @@ public: if(info && (value = info->getChild(Constants::Duration))) { length = static_cast(value->getAsFloat()); if((value = info->getChild(Constants::TimecodeScale))){ - length /= (value->getAsUnsigned() * (1 / 1000000000)); + length = static_cast(length / (value->getAsUnsigned() * (1.0 / 1000000000))); } } @@ -59,10 +59,10 @@ public: // Dirty bitrate: document->seek(0, File::End); - bitrate = ((8 * document->tell()) / length) / 1000; + bitrate = static_cast(8 * document->tell() / length / 1000); if((value = info->getChild(Constants::Channels))) - channels = value->getAsUnsigned(); + channels = static_cast(value->getAsUnsigned()); if((value = info->getChild(Constants::SamplingFrequency))) samplerate = static_cast(value->getAsFloat()); diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp index 4743a505..8dabd689 100644 --- a/taglib/mpeg/mpegfile.cpp +++ b/taglib/mpeg/mpegfile.cpp @@ -374,7 +374,8 @@ offset_t MPEG::File::previousFrameOffset(offset_t position) ByteVector buffer; while (position > 0) { - uint size = position < static_cast(bufferSize()) ? static_cast(position) : bufferSize(); + size_t size = position < static_cast(bufferSize()) + ? static_cast(position) : bufferSize(); position -= size; seek(position); diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index c20b3910..e3ef13d5 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -65,7 +65,7 @@ namespace size_t fread(void *ptr, size_t size, size_t nmemb, HANDLE stream) { DWORD readLen; - if(ReadFile(stream, ptr, size * nmemb, &readLen, NULL)) + if(ReadFile(stream, ptr, static_cast(size * nmemb), &readLen, NULL)) return (readLen / size); else return 0; @@ -74,7 +74,7 @@ namespace size_t fwrite(const void *ptr, size_t size, size_t nmemb, HANDLE stream) { DWORD writtenLen; - if(WriteFile(stream, ptr, size * nmemb, &writtenLen, NULL)) + if(WriteFile(stream, ptr, static_cast(size * nmemb), &writtenLen, NULL)) return (writtenLen / size); else return 0;