From 5c2da08c1308ddbed48187c02f6507625bba4e45 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 26 Aug 2013 13:50:07 -0700 Subject: [PATCH] Fix warnings --- .../beast_core/containers/beast_Variant.cpp | 4 +- modules/beast_core/files/beast_File.cpp | 2 +- modules/beast_core/files/beast_File.h | 2 +- .../files/beast_FileOutputStream.cpp | 6 +-- .../beast_core/files/beast_FileOutputStream.h | 2 +- .../beast_core/memory/beast_MemoryBlock.cpp | 54 ++++++++----------- .../native/beast_posix_SharedCode.h | 2 +- .../beast_core/network/beast_IPAddress.cpp | 6 +-- .../beast_core/streams/beast_OutputStream.cpp | 8 +-- modules/beast_core/xml/beast_XmlElement.cpp | 8 +-- .../zip/beast_GZIPCompressorOutputStream.cpp | 2 +- 11 files changed, 42 insertions(+), 54 deletions(-) diff --git a/modules/beast_core/containers/beast_Variant.cpp b/modules/beast_core/containers/beast_Variant.cpp index bd27a10bb5..943064a7c4 100644 --- a/modules/beast_core/containers/beast_Variant.cpp +++ b/modules/beast_core/containers/beast_Variant.cpp @@ -673,12 +673,12 @@ var var::readFromStream (InputStream& input) case varMarker_Binary: { - MemoryBlock mb (numBytes - 1); + MemoryBlock mb ((size_t) numBytes - 1); if (numBytes > 1) { const int numRead = input.read (mb.getData(), numBytes - 1); - mb.setSize (numRead); + mb.setSize ((size_t) numRead); } return var (mb); diff --git a/modules/beast_core/files/beast_File.cpp b/modules/beast_core/files/beast_File.cpp index 39c04b22ee..c980ff7aa0 100644 --- a/modules/beast_core/files/beast_File.cpp +++ b/modules/beast_core/files/beast_File.cpp @@ -687,7 +687,7 @@ FileInputStream* File::createInputStream() const return nullptr; } -FileOutputStream* File::createOutputStream (const int bufferSize) const +FileOutputStream* File::createOutputStream (const size_t bufferSize) const { ScopedPointer out (new FileOutputStream (*this, bufferSize)); diff --git a/modules/beast_core/files/beast_File.h b/modules/beast_core/files/beast_File.h index 9566a5ece8..22f32b9320 100644 --- a/modules/beast_core/files/beast_File.h +++ b/modules/beast_core/files/beast_File.h @@ -585,7 +585,7 @@ public: end of the file), or nullptr if the file can't be opened for some reason @see createInputStream, appendData, appendText */ - FileOutputStream* createOutputStream (int bufferSize = 0x8000) const; + FileOutputStream* createOutputStream (size_t bufferSize = 0x8000) const; //============================================================================== /** Loads a file's contents into memory as a block of binary data. diff --git a/modules/beast_core/files/beast_FileOutputStream.cpp b/modules/beast_core/files/beast_FileOutputStream.cpp index a3a0e5e3c6..b7f24708f3 100644 --- a/modules/beast_core/files/beast_FileOutputStream.cpp +++ b/modules/beast_core/files/beast_FileOutputStream.cpp @@ -24,14 +24,14 @@ int64 beast_fileSetPosition (void* handle, int64 pos); //============================================================================== -FileOutputStream::FileOutputStream (const File& f, const int bufferSize_) +FileOutputStream::FileOutputStream (const File& f, const size_t bufferSizeToUse) : file (f), fileHandle (nullptr), status (Result::ok()), currentPosition (0), - bufferSize (bufferSize_), + bufferSize (bufferSizeToUse), bytesInBuffer (0), - buffer ((size_t) bmax (bufferSize_, 16)) + buffer (bmax (bufferSizeToUse, (size_t) 16)) { openHandle(); } diff --git a/modules/beast_core/files/beast_FileOutputStream.h b/modules/beast_core/files/beast_FileOutputStream.h index e4110492c9..0cc8eaa7de 100644 --- a/modules/beast_core/files/beast_FileOutputStream.h +++ b/modules/beast_core/files/beast_FileOutputStream.h @@ -53,7 +53,7 @@ public: @see TemporaryFile */ FileOutputStream (const File& fileToWriteTo, - int bufferSizeToUse = 16384); + size_t bufferSizeToUse = 16384); /** Destructor. */ ~FileOutputStream(); diff --git a/modules/beast_core/memory/beast_MemoryBlock.cpp b/modules/beast_core/memory/beast_MemoryBlock.cpp index e040dff781..c4c016ba18 100644 --- a/modules/beast_core/memory/beast_MemoryBlock.cpp +++ b/modules/beast_core/memory/beast_MemoryBlock.cpp @@ -224,12 +224,12 @@ void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) noexc if (offset < 0) { d -= offset; - num -= offset; + num += (size_t) -offset; offset = 0; } - if (offset + num > size) - num = size - offset; + if ((size_t) offset + num > size) + num = size - (size_t) offset; if (num > 0) memcpy (data + offset, d, num); @@ -243,14 +243,13 @@ void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const noexcep { zeromem (d, (size_t) -offset); d -= offset; - - num += offset; + num -= (size_t) -offset; offset = 0; } - if (offset + num > size) + if ((size_t) offset + num > size) { - const size_t newNum = size - offset; + const size_t newNum = size - (size_t) offset; zeromem (d + newNum, num - newNum); num = newNum; } @@ -270,12 +269,12 @@ int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const int res = 0; size_t byte = bitRangeStart >> 3; - int offsetInByte = (int) bitRangeStart & 7; + size_t offsetInByte = bitRangeStart & 7; size_t bitsSoFar = 0; while (numBits > 0 && (size_t) byte < size) { - const int bitsThisTime = bmin ((int) numBits, 8 - offsetInByte); + const size_t bitsThisTime = bmin (numBits, 8 - offsetInByte); const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte; res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar); @@ -292,17 +291,17 @@ int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) noexcept { size_t byte = bitRangeStart >> 3; - int offsetInByte = (int) bitRangeStart & 7; - unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits)); + size_t offsetInByte = bitRangeStart & 7; + uint32 mask = ~((((uint32) 0xffffffff) << (32 - numBits)) >> (32 - numBits)); while (numBits > 0 && (size_t) byte < size) { - const int bitsThisTime = bmin ((int) numBits, 8 - offsetInByte); + const size_t bitsThisTime = bmin (numBits, 8 - offsetInByte); - const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte); - const unsigned int tempBits = (unsigned int) bitsToSet << offsetInByte; + const uint32 tempMask = (mask << offsetInByte) | ~((((uint32) 0xffffffff) >> offsetInByte) << offsetInByte); + const uint32 tempBits = (uint32) bitsToSet << offsetInByte; - data[byte] = (char) ((data[byte] & tempMask) | tempBits); + data[byte] = (char) (((uint32) data[byte] & tempMask) | tempBits); ++byte; numBits -= bitsThisTime; @@ -331,22 +330,11 @@ void MemoryBlock::loadFromHexString (const String& hex) { const beast_wchar c = t.getAndAdvance(); - if (c >= '0' && c <= '9') - { - byte |= c - '0'; - break; - } - else if (c >= 'a' && c <= 'z') - { - byte |= c - ('a' - 10); - break; - } - else if (c >= 'A' && c <= 'Z') - { - byte |= c - ('A' - 10); - break; - } - else if (c == 0) + if (c >= '0' && c <= '9') { byte |= c - '0'; break; } + if (c >= 'a' && c <= 'z') { byte |= c - ('a' - 10); break; } + if (c >= 'A' && c <= 'Z') { byte |= c - ('A' - 10); break; } + + if (c == 0) { setSize (static_cast (dest - data)); return; @@ -367,7 +355,7 @@ String MemoryBlock::toBase64Encoding() const String destString ((unsigned int) size); // store the length, followed by a '.', and then the data. const int initialLen = destString.length(); - destString.preallocateBytes (sizeof (String::CharPointerType::CharType) * (size_t) (initialLen + 2 + numChars)); + destString.preallocateBytes (sizeof (String::CharPointerType::CharType) * (size_t) initialLen + 2 + numChars); String::CharPointerType d (destString.getCharPointer()); d += initialLen; @@ -413,4 +401,4 @@ bool MemoryBlock::fromBase64Encoding (const String& s) } return true; -} +} \ No newline at end of file diff --git a/modules/beast_core/native/beast_posix_SharedCode.h b/modules/beast_core/native/beast_posix_SharedCode.h index cb686d260a..93126fa0a7 100644 --- a/modules/beast_core/native/beast_posix_SharedCode.h +++ b/modules/beast_core/native/beast_posix_SharedCode.h @@ -1327,7 +1327,7 @@ struct HighResolutionTimer::Pimpl : public Uncopyable shouldStop = false; if (pthread_create (&thread, nullptr, timerThread, this) == 0) - setThreadToRealtime (thread, newPeriod); + setThreadToRealtime (thread, (uint64) newPeriod); else bassertfalse; } diff --git a/modules/beast_core/network/beast_IPAddress.cpp b/modules/beast_core/network/beast_IPAddress.cpp index 789cc46f4c..08e69bee33 100644 --- a/modules/beast_core/network/beast_IPAddress.cpp +++ b/modules/beast_core/network/beast_IPAddress.cpp @@ -96,12 +96,12 @@ static void findIPAddresses (int sock, Array& result) { ifconf cfg; HeapBlock buffer; - size_t bufferSize = 1024; + int bufferSize = 1024; do { bufferSize *= 2; - buffer.calloc (bufferSize); + buffer.calloc ((size_t)bufferSize); cfg.ifc_len = bufferSize; cfg.ifc_buf = buffer; @@ -109,7 +109,7 @@ static void findIPAddresses (int sock, Array& result) if (ioctl (sock, SIOCGIFCONF, &cfg) < 0 && errno != EINVAL) return; - } while (bufferSize < cfg.ifc_len + 2 * (IFNAMSIZ + sizeof (struct sockaddr_in6))); + } while (bufferSize < cfg.ifc_len + 2 * (int) (IFNAMSIZ + sizeof (struct sockaddr_in6))); #if BEAST_MAC || BEAST_IOS while (cfg.ifc_len >= (int) (IFNAMSIZ + sizeof (struct sockaddr_in))) diff --git a/modules/beast_core/streams/beast_OutputStream.cpp b/modules/beast_core/streams/beast_OutputStream.cpp index 614b32e1db..e11249b8e5 100644 --- a/modules/beast_core/streams/beast_OutputStream.cpp +++ b/modules/beast_core/streams/beast_OutputStream.cpp @@ -142,7 +142,7 @@ bool OutputStream::writeCompressedInt (int value) if (value < 0) data[0] |= 0x80; - return write (data, num + 1); + return write (data, (size_t) num + 1); } bool OutputStream::writeInt64 (int64 value) @@ -232,7 +232,7 @@ bool OutputStream::writeText (const String& text, const bool asUTF16, if (*t == '\n') { if (t > src) - if (! write (src, (int) (t - src))) + if (! write (src, (size_t) (t - src))) return false; if (! write ("\r\n", 2)) @@ -248,7 +248,7 @@ bool OutputStream::writeText (const String& text, const bool asUTF16, else if (*t == 0) { if (t > src) - if (! write (src, (int) (t - src))) + if (! write (src, (size_t) (t - src))) return false; break; @@ -276,7 +276,7 @@ int OutputStream::writeFromInputStream (InputStream& source, int64 numBytesToWri if (num <= 0) break; - write (buffer, num); + write (buffer, (size_t) num); numBytesToWrite -= num; numWritten += num; diff --git a/modules/beast_core/xml/beast_XmlElement.cpp b/modules/beast_core/xml/beast_XmlElement.cpp index 9c992c9c6b..5c48d9f57d 100644 --- a/modules/beast_core/xml/beast_XmlElement.cpp +++ b/modules/beast_core/xml/beast_XmlElement.cpp @@ -204,7 +204,7 @@ namespace XmlOutputFunctions } } - static void writeSpaces (OutputStream& out, const int numSpaces) + static void writeSpaces (OutputStream& out, const size_t numSpaces) { out.writeRepeatedByte (' ', numSpaces); } @@ -217,7 +217,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, using namespace XmlOutputFunctions; if (indentationLevel >= 0) - writeSpaces (outputStream, indentationLevel); + writeSpaces (outputStream, (size_t) indentationLevel); if (! isTextElement()) { @@ -225,7 +225,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, outputStream << tagName; { - const int attIndent = indentationLevel + tagName.length() + 1; + const size_t attIndent = (size_t) (indentationLevel + tagName.length() + 1); int lineLen = 0; for (const XmlAttributeNode* att = attributes; att != nullptr; att = att->nextListItem) @@ -274,7 +274,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, if (indentationLevel >= 0 && ! lastWasTextNode) { outputStream << newLine; - writeSpaces (outputStream, indentationLevel); + writeSpaces (outputStream, (size_t) indentationLevel); } outputStream.write ("