diff options
author | Jose <jose@zeroc.com> | 2019-06-22 00:29:53 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2019-06-22 00:29:53 +0200 |
commit | c5959fd09de61604bedd75354401df6a57395d65 (patch) | |
tree | 3b0227f631c8b20fb1a1a274b92f63f52f34af2c /cpp/src/Ice | |
parent | Small fix (diff) | |
parent | Enable -Wconversion with clang - Close #363 (diff) | |
download | ice-c5959fd09de61604bedd75354401df6a57395d65.tar.bz2 ice-c5959fd09de61604bedd75354401df6a57395d65.tar.xz ice-c5959fd09de61604bedd75354401df6a57395d65.zip |
Merge remote-tracking branch 'origin/3.7' into swift
Diffstat (limited to 'cpp/src/Ice')
-rw-r--r-- | cpp/src/Ice/ArgVector.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Ice/Base64.cpp | 22 | ||||
-rw-r--r-- | cpp/src/Ice/BatchRequestQueue.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Buffer.cpp | 4 | ||||
-rw-r--r-- | cpp/src/Ice/ConnectionI.cpp | 12 | ||||
-rw-r--r-- | cpp/src/Ice/HashUtil.h | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Initialize.cpp | 7 | ||||
-rw-r--r-- | cpp/src/Ice/InputStream.cpp | 38 | ||||
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 13 | ||||
-rwxr-xr-x | cpp/src/Ice/Network.cpp | 15 | ||||
-rw-r--r-- | cpp/src/Ice/Object.cpp | 7 | ||||
-rw-r--r-- | cpp/src/Ice/OutputStream.cpp | 48 | ||||
-rw-r--r-- | cpp/src/Ice/ProxyFactory.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/ReferenceFactory.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Selector.cpp | 7 | ||||
-rw-r--r-- | cpp/src/Ice/Service.cpp | 6 | ||||
-rwxr-xr-x | cpp/src/Ice/StreamSocket.cpp | 12 | ||||
-rwxr-xr-x | cpp/src/Ice/UdpTransceiver.cpp | 12 | ||||
-rw-r--r-- | cpp/src/Ice/WSTransceiver.cpp | 31 |
19 files changed, 130 insertions, 118 deletions
diff --git a/cpp/src/Ice/ArgVector.cpp b/cpp/src/Ice/ArgVector.cpp index ee1d60af61b..48ce959524f 100644 --- a/cpp/src/Ice/ArgVector.cpp +++ b/cpp/src/Ice/ArgVector.cpp @@ -8,8 +8,8 @@ IceInternal::ArgVector::ArgVector(int argcP, const char* const argvP[]) { assert(argcP >= 0); - _args.resize(argcP); - for(int i = 0; i < argcP; ++i) + _args.resize(static_cast<size_t>(argcP)); + for(size_t i = 0; i < static_cast<size_t>(argcP); ++i) { _args[i] = argvP[i]; } @@ -51,7 +51,7 @@ IceInternal::ArgVector::setupArgcArgv() { throw ::std::bad_alloc(); } - for(int i = 0; i < argc; i++) + for(size_t i = 0; i < static_cast<size_t>(argc); i++) { argv[i] = const_cast<char*>(_args[i].c_str()); } diff --git a/cpp/src/Ice/Base64.cpp b/cpp/src/Ice/Base64.cpp index ea2427df92b..488f59c39c6 100644 --- a/cpp/src/Ice/Base64.cpp +++ b/cpp/src/Ice/Base64.cpp @@ -49,8 +49,8 @@ IceInternal::Base64::encode(const vector<unsigned char>& plainSeq) } by4 = by1 >> 2; - by5 = ((by1 & 0x3) << 4) | (by2 >> 4); - by6 = ((by2 & 0xf) << 2) | (by3 >> 6); + by5 = static_cast<unsigned char>((by1 & 0x3) << 4) | (by2 >> 4); + by6 = static_cast<unsigned char>((by2 & 0xf) << 2) | (by3 >> 6); by7 = by3 & 0x3f; retval += encode(by4); @@ -158,16 +158,16 @@ IceInternal::Base64::decode(const string& str) by3 = decode(c3); by4 = decode(c4); - retval.push_back((by1 << 2) | (by2 >> 4)); + retval.push_back(static_cast<unsigned char>(by1 << 2) | (by2 >> 4)); if(c3 != '=') { - retval.push_back(((by2 & 0xf) << 4) | (by3 >> 2)); + retval.push_back(static_cast<unsigned char>((by2 & 0xf) << 4) | (by3 >> 2)); } if(c4 != '=') { - retval.push_back(((by3 & 0x3) << 6) | by4); + retval.push_back(static_cast<unsigned char>((by3 & 0x3) << 6) | by4); } } @@ -215,17 +215,17 @@ IceInternal::Base64::encode(unsigned char uc) { if(uc < 26) { - return 'A' + uc; + return 'A' + static_cast<char>(uc); } if(uc < 52) { - return 'a' + (uc - 26); + return 'a' + static_cast<char>(uc) - 26; } if(uc < 62) { - return '0' + (uc - 52); + return '0' + static_cast<char>(uc) - 52; } if(uc == 62) @@ -241,17 +241,17 @@ IceInternal::Base64::decode(char c) { if(c >= 'A' && c <= 'Z') { - return c - 'A'; + return static_cast<unsigned char>(c - 'A'); } if(c >= 'a' && c <= 'z') { - return c - 'a' + 26; + return static_cast<unsigned char>(c - 'a' + 26); } if(c >= '0' && c <= '9') { - return c - '0' + 52; + return static_cast<unsigned char>(c - '0' + 52); } if(c == '+') diff --git a/cpp/src/Ice/BatchRequestQueue.cpp b/cpp/src/Ice/BatchRequestQueue.cpp index 32ba60cc0f9..5fb44746696 100644 --- a/cpp/src/Ice/BatchRequestQueue.cpp +++ b/cpp/src/Ice/BatchRequestQueue.cpp @@ -76,7 +76,7 @@ BatchRequestQueue::BatchRequestQueue(const InstancePtr& instance, bool datagram) if(_maxSize > 0 && datagram) { const Ice::InitializationData& initData = instance->initializationData(); - size_t udpSndSize = initData.properties->getPropertyAsIntWithDefault("Ice.UDP.SndSize", 65535 - udpOverhead); + size_t udpSndSize = static_cast<size_t>(initData.properties->getPropertyAsIntWithDefault("Ice.UDP.SndSize", 65535 - udpOverhead)); if(udpSndSize < _maxSize) { _maxSize = udpSndSize; diff --git a/cpp/src/Ice/Buffer.cpp b/cpp/src/Ice/Buffer.cpp index 8b4c6f9062a..50e5d52a9c7 100644 --- a/cpp/src/Ice/Buffer.cpp +++ b/cpp/src/Ice/Buffer.cpp @@ -27,8 +27,8 @@ IceInternal::Buffer::Container::Container() : IceInternal::Buffer::Container::Container(const_iterator beg, const_iterator end) : _buf(const_cast<iterator>(beg)), - _size(end - beg), - _capacity(end - beg), + _size(static_cast<size_t>(end - beg)), + _capacity(static_cast<size_t>(end - beg)), _shrinkCounter(0), _owned(false) { diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index 1666717289f..176848c84f8 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -1685,11 +1685,11 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current) } if(size > static_cast<Int>(_messageSizeMax)) { - Ex::throwMemoryLimitException(__FILE__, __LINE__, size, _messageSizeMax); + Ex::throwMemoryLimitException(__FILE__, __LINE__, static_cast<size_t>(size), _messageSizeMax); } - if(size > static_cast<Int>(_readStream.b.size())) + if(static_cast<size_t>(size) > _readStream.b.size()) { - _readStream.b.resize(size); + _readStream.b.resize(static_cast<size_t>(size)); } _readStream.i = _readStream.b.begin() + pos; } @@ -3195,11 +3195,11 @@ Ice::ConnectionI::doUncompress(InputStream& compressed, InputStream& uncompresse if(uncompressedSize > static_cast<Int>(_messageSizeMax)) { - Ex::throwMemoryLimitException(__FILE__, __LINE__, uncompressedSize, _messageSizeMax); + Ex::throwMemoryLimitException(__FILE__, __LINE__, static_cast<size_t>(uncompressedSize), _messageSizeMax); } - uncompressed.resize(uncompressedSize); + uncompressed.resize(static_cast<size_t>(uncompressedSize)); - unsigned int uncompressedLen = uncompressedSize - headerSize; + unsigned int uncompressedLen = static_cast<unsigned int>(uncompressedSize - headerSize); unsigned int compressedLen = static_cast<unsigned int>(compressed.b.size() - headerSize - sizeof(Int)); int bzError = BZ2_bzBuffToBuffDecompress(reinterpret_cast<char*>(&uncompressed.b[0]) + headerSize, &uncompressedLen, diff --git a/cpp/src/Ice/HashUtil.h b/cpp/src/Ice/HashUtil.h index e565bb5df28..1a543d9a21c 100644 --- a/cpp/src/Ice/HashUtil.h +++ b/cpp/src/Ice/HashUtil.h @@ -11,7 +11,7 @@ namespace IceInternal inline void hashAdd(Ice::Int& hashCode, Ice::Int value) { - hashCode = ((hashCode << 5) + hashCode) ^ (2654435761u * value); + hashCode = ((hashCode << 5) + hashCode) ^ static_cast<Ice::Int>(2654435761u) * value; } inline void diff --git a/cpp/src/Ice/Initialize.cpp b/cpp/src/Ice/Initialize.cpp index 70f48b781ac..1dfd7290b8f 100644 --- a/cpp/src/Ice/Initialize.cpp +++ b/cpp/src/Ice/Initialize.cpp @@ -570,11 +570,12 @@ Ice::stringToIdentity(const string& s) // Find unescaped separator; note that the string may contain an escaped // backslash before the separator. // - string::size_type slash = string::npos, pos = 0; + string::size_type slash = string::npos; + string::size_type pos = 0; while((pos = s.find('/', pos)) != string::npos) { - int escapes = 0; - while(static_cast<int>(pos) - escapes > 0 && s[pos - escapes - 1] == '\\') + string::size_type escapes = 0; + while(static_cast<int>(pos - escapes) > 0 && s[pos - escapes - 1] == '\\') { escapes++; } diff --git a/cpp/src/Ice/InputStream.cpp b/cpp/src/Ice/InputStream.cpp index 79ba83ed174..9f85122928d 100644 --- a/cpp/src/Ice/InputStream.cpp +++ b/cpp/src/Ice/InputStream.cpp @@ -331,7 +331,7 @@ Ice::InputStream::skipEncapsulation() EncodingVersion encoding; read(encoding.major); read(encoding.minor); - i += sz - sizeof(Int) - 2; + i += static_cast<size_t>(sz) - sizeof(Int) - 2; return encoding; } @@ -432,7 +432,7 @@ Ice::InputStream::read(std::vector<Ice::Byte>& v) read(p); if(p.first != p.second) { - v.resize(static_cast<Ice::Int>(p.second - p.first)); + v.resize(static_cast<size_t>(p.second - p.first)); copy(p.first, p.second, v.begin()); } else @@ -463,7 +463,7 @@ Ice::InputStream::read(vector<bool>& v) Int sz = readAndCheckSeqSize(1); if(sz > 0) { - v.resize(sz); + v.resize(static_cast<size_t>(sz)); copy(i, i + sz, v.begin()); i += sz; } @@ -571,7 +571,7 @@ Ice::InputStream::read(vector<Short>& v) { Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Short)); - v.resize(sz); + v.resize(static_cast<size_t>(sz)); #ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Short) - 1; @@ -651,7 +651,7 @@ Ice::InputStream::read(vector<Int>& v) { Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Int)); - v.resize(sz); + v.resize(static_cast<size_t>(sz)); #ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Int) - 1; @@ -768,7 +768,7 @@ Ice::InputStream::read(vector<Long>& v) { Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Long)); - v.resize(sz); + v.resize(static_cast<size_t>(sz)); #ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Long) - 1; @@ -885,7 +885,7 @@ Ice::InputStream::read(vector<Float>& v) { Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Float)); - v.resize(sz); + v.resize(static_cast<size_t>(sz)); #ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Float) - 1; @@ -1002,7 +1002,7 @@ Ice::InputStream::read(vector<Double>& v) { Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Double)); - v.resize(sz); + v.resize(static_cast<size_t>(sz)); #ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); Byte* dest = reinterpret_cast<Byte*>(&v[0]) + sizeof(Double) - 1; @@ -1266,8 +1266,8 @@ Ice::InputStream::read(vector<string>& v, bool convert) Int sz = readAndCheckSeqSize(1); if(sz > 0) { - v.resize(sz); - for(int j = 0; j < sz; ++j) + v.resize(static_cast<size_t>(sz)); + for(size_t j = 0; j < static_cast<size_t>(sz); ++j) { read(v[j], convert); } @@ -1318,11 +1318,11 @@ Ice::InputStream::read(wstring& v) void Ice::InputStream::read(vector<wstring>& v) { - Int sz = readAndCheckSeqSize(1); + size_t sz = static_cast<size_t>(readAndCheckSeqSize(1)); if(sz > 0) { v.resize(sz); - for(int j = 0; j < sz; ++j) + for(size_t j = 0; j < sz; ++j) { read(v[j]); } @@ -1479,7 +1479,7 @@ Ice::InputStream::skipOptional(OptionalFormat type) } case ICE_SCOPED_ENUM(OptionalFormat, VSize): { - skip(readSize()); + skip(static_cast<size_t>(readSize())); break; } case ICE_SCOPED_ENUM(OptionalFormat, FSize): @@ -1490,7 +1490,7 @@ Ice::InputStream::skipOptional(OptionalFormat type) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } - skip(sz); + skip(static_cast<size_t>(sz)); break; } case ICE_SCOPED_ENUM(OptionalFormat, Class): @@ -2116,7 +2116,7 @@ Ice::InputStream::EncapsDecoder10::skipSlice() { _stream->traceSkipSlice(_typeId, _sliceType); assert(_sliceSize >= 4); - _stream->skip(_sliceSize - sizeof(Int)); + _stream->skip(static_cast<size_t>(_sliceSize) - sizeof(Int)); } void @@ -2446,7 +2446,7 @@ Ice::InputStream::EncapsDecoder11::endSlice() // if(_current->sliceFlags & FLAG_HAS_INDIRECTION_TABLE) { - IndexList indirectionTable(_stream->readAndCheckSeqSize(1)); + IndexList indirectionTable(static_cast<size_t>(_stream->readAndCheckSeqSize(1))); for(IndexList::iterator p = indirectionTable.begin(); p != indirectionTable.end(); ++p) { *p = readInstance(_stream->readSize(), 0, 0); @@ -2477,7 +2477,7 @@ Ice::InputStream::EncapsDecoder11::endSlice() { throw MarshalException(__FILE__, __LINE__, "indirection out of range"); } - addPatchEntry(indirectionTable[p->index], p->patchFunc, p->patchAddr); + addPatchEntry(indirectionTable[static_cast<size_t>(p->index)], p->patchFunc, p->patchAddr); } _current->indirectPatchList.clear(); } @@ -2493,7 +2493,7 @@ Ice::InputStream::EncapsDecoder11::skipSlice() if(_current->sliceFlags & FLAG_HAS_SLICE_SIZE) { assert(_current->sliceSize >= 4); - _stream->skip(_current->sliceSize - sizeof(Int)); + _stream->skip(static_cast<size_t>(_current->sliceSize) - sizeof(Int)); } else { @@ -2544,7 +2544,7 @@ Ice::InputStream::EncapsDecoder11::skipSlice() if(_current->sliceFlags & FLAG_HAS_INDIRECTION_TABLE) { IndexList& table = _current->indirectionTables.back(); - table.resize(_stream->readAndCheckSeqSize(1)); + table.resize(static_cast<size_t>(_stream->readAndCheckSeqSize(1))); for(IndexList::iterator p = table.begin(); p != table.end(); ++p) { *p = readInstance(_stream->readSize(), 0, 0); diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 240fe7c867e..e0c06b52a9b 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -1037,7 +1037,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi throw SyscallException(__FILE__, __LINE__, getSystemErrno()); } - if(initgroups(pw->pw_name, pw->pw_gid) == -1) + if(initgroups(pw->pw_name, static_cast<int>(pw->pw_gid)) == -1) { throw SyscallException(__FILE__, __LINE__, getSystemErrno()); } @@ -1122,8 +1122,13 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi #endif if(!logfile.empty()) { - _initData.logger = ICE_MAKE_SHARED(LoggerI, _initData.properties->getProperty("Ice.ProgramName"), logfile, true, - _initData.properties->getPropertyAsIntWithDefault("Ice.LogFile.SizeMax", 0)); + Int sz = _initData.properties->getPropertyAsIntWithDefault("Ice.LogFile.SizeMax", 0); + if(sz < 0) + { + sz = 0; + } + _initData.logger = ICE_MAKE_SHARED(LoggerI, _initData.properties->getProperty("Ice.ProgramName"), + logfile, true, static_cast<size_t>(sz)); } else { @@ -1180,7 +1185,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi Int num = _initData.properties->getPropertyAsIntWithDefault("Ice.BatchAutoFlushSize", 1024); // 1MB default if(num < 1) { - const_cast<size_t&>(_batchAutoFlushSize) = num; + const_cast<size_t&>(_batchAutoFlushSize) = static_cast<size_t>(num); } else if(static_cast<size_t>(num) > static_cast<size_t>(0x7fffffff / 1024)) { diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp index 19aac9ec2c4..d1e4b8194ee 100755 --- a/cpp/src/Ice/Network.cpp +++ b/cpp/src/Ice/Network.cpp @@ -660,7 +660,7 @@ getInterfaceIndex(const string& intf) struct sockaddr_in6* ipv6Addr = reinterpret_cast<struct sockaddr_in6*>(curr->ifa_addr); if(memcmp(&addr, &ipv6Addr->sin6_addr, sizeof(in6_addr)) == 0) { - index = if_nametoindex(curr->ifa_name); + index = static_cast<int>(if_nametoindex(curr->ifa_name)); break; } } @@ -725,7 +725,7 @@ getInterfaceIndex(const string& intf) struct sockaddr_in6* ipv6Addr = reinterpret_cast<struct sockaddr_in6*>(&ifr[i].ifr_addr); if(memcmp(&addr, &ipv6Addr->sin6_addr, sizeof(in6_addr)) == 0) { - index = if_nametoindex(ifr[i].ifr_name); + index = static_cast<int>(if_nametoindex(ifr[i].ifr_name)); break; } } @@ -736,7 +736,7 @@ getInterfaceIndex(const string& intf) } else // Look for an interface with the given name. { - index = if_nametoindex(name.c_str()); + index = static_cast<int>(if_nametoindex(name.c_str())); } if(index <= 0) { @@ -1821,7 +1821,8 @@ IceInternal::inetAddrToString(const Address& ss) char namebuf[1024]; namebuf[0] = '\0'; - getnameinfo(&ss.sa, size, namebuf, static_cast<socklen_t>(sizeof(namebuf)), 0, 0, NI_NUMERICHOST); + getnameinfo(&ss.sa, static_cast<socklen_t>(size), namebuf, static_cast<socklen_t>(sizeof(namebuf)), 0, 0, + NI_NUMERICHOST); return string(namebuf); #else if(ss.host == nullptr) @@ -2161,7 +2162,7 @@ IceInternal::setMcastGroup(SOCKET fd, const Address& group, const string& intf) indexes.insert(index); struct ipv6_mreq mreq; mreq.ipv6mr_multiaddr = group.saIn6.sin6_addr; - mreq.ipv6mr_interface = index; + mreq.ipv6mr_interface = static_cast<unsigned int>(index); rc = setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, reinterpret_cast<char*>(&mreq), int(sizeof(mreq))); } } @@ -2404,7 +2405,7 @@ IceInternal::doBind(SOCKET fd, const Address& addr, const string&) int size = getAddressStorageSize(addr); assert(size != 0); - if(::bind(fd, &addr.sa, size) == SOCKET_ERROR) + if(::bind(fd, &addr.sa, static_cast<socklen_t>(size)) == SOCKET_ERROR) { closeSocketNoThrow(fd); throw SocketException(__FILE__, __LINE__, getSocketErrno()); @@ -2626,7 +2627,7 @@ repeatConnect: int size = getAddressStorageSize(addr); assert(size != 0); - if(::connect(fd, &addr.sa, size) == SOCKET_ERROR) + if(::connect(fd, &addr.sa, static_cast<socklen_t>(size)) == SOCKET_ERROR) { if(interrupted()) { diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp index d5509a24b5f..effce176db2 100644 --- a/cpp/src/Ice/Object.cpp +++ b/cpp/src/Ice/Object.cpp @@ -319,17 +319,12 @@ Ice::Object::_iceCheckMode(OperationMode expected, OperationMode received) { if(expected != received) { + assert(expected != ICE_ENUM(OperationMode, Nonmutating)); // We never expect Nonmutating if(expected == ICE_ENUM(OperationMode, Idempotent) && received == ICE_ENUM(OperationMode, Nonmutating)) { // // Fine: typically an old client still using the deprecated nonmutating keyword // - - // - // Note that expected == Nonmutating and received == Idempotent is not ok: - // the server may still use the deprecated nonmutating keyword to detect updates - // and the client should not break this (deprecated) feature. - // } else { diff --git a/cpp/src/Ice/OutputStream.cpp b/cpp/src/Ice/OutputStream.cpp index e316ec634f4..7493116de2d 100644 --- a/cpp/src/Ice/OutputStream.cpp +++ b/cpp/src/Ice/OutputStream.cpp @@ -42,7 +42,7 @@ public: // // Return unused bytes // - _stream.resize(firstUnused - _stream.b.begin()); + _stream.resize(static_cast<size_t>(firstUnused - _stream.b.begin())); } // @@ -255,8 +255,8 @@ Ice::OutputStream::write(const Byte* begin, const Byte* end) if(sz > 0) { Container::size_type pos = b.size(); - resize(pos + sz); - memcpy(&b[pos], begin, sz); + resize(pos + static_cast<size_t>(sz)); + memcpy(&b[pos], begin, static_cast<size_t>(sz)); } } @@ -268,7 +268,7 @@ Ice::OutputStream::write(const vector<bool>& v) if(sz > 0) { Container::size_type pos = b.size(); - resize(pos + sz); + resize(pos + static_cast<size_t>(sz)); copy(v.begin(), v.end(), b.begin() + pos); } } @@ -281,9 +281,9 @@ struct WriteBoolHelper { static void write(const bool* begin, OutputStream::Container::size_type pos, OutputStream::Container& b, Int sz) { - for(int idx = 0; idx < sz; ++idx) + for(size_t idx = 0; idx < static_cast<size_t>(sz); ++idx) { - b[pos + idx] = static_cast<Byte>(*(begin + idx)); + b[pos + idx] = static_cast<Byte>(*(begin + idx)); } } }; @@ -293,7 +293,7 @@ struct WriteBoolHelper<1> { static void write(const bool* begin, OutputStream::Container::size_type pos, OutputStream::Container& b, Int sz) { - memcpy(&b[pos], begin, sz); + memcpy(&b[pos], begin, static_cast<size_t>(sz)); } }; @@ -307,7 +307,7 @@ Ice::OutputStream::write(const bool* begin, const bool* end) if(sz > 0) { Container::size_type pos = b.size(); - resize(pos + sz); + resize(pos + static_cast<size_t>(sz)); WriteBoolHelper<sizeof(bool)>::write(begin, pos, b, sz); } } @@ -337,7 +337,7 @@ Ice::OutputStream::write(const Short* begin, const Short* end) if(sz > 0) { Container::size_type pos = b.size(); - resize(pos + sz * sizeof(Short)); + resize(pos + static_cast<size_t>(sz) * sizeof(Short)); #ifdef ICE_BIG_ENDIAN const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Short) - 1; Byte* dest = &(*(b.begin() + pos)); @@ -348,7 +348,7 @@ Ice::OutputStream::write(const Short* begin, const Short* end) src += 2 * sizeof(Short); } #else - memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Short)); + memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), static_cast<size_t>(sz) * sizeof(Short)); #endif } } @@ -361,7 +361,7 @@ Ice::OutputStream::write(const Int* begin, const Int* end) if(sz > 0) { Container::size_type pos = b.size(); - resize(pos + sz * sizeof(Int)); + resize(pos + static_cast<size_t>(sz) * sizeof(Int)); #ifdef ICE_BIG_ENDIAN const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Int) - 1; Byte* dest = &(*(b.begin() + pos)); @@ -374,7 +374,7 @@ Ice::OutputStream::write(const Int* begin, const Int* end) src += 2 * sizeof(Int); } #else - memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Int)); + memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), static_cast<size_t>(sz) * sizeof(Int)); #endif } } @@ -416,7 +416,7 @@ Ice::OutputStream::write(const Long* begin, const Long* end) if(sz > 0) { Container::size_type pos = b.size(); - resize(pos + sz * sizeof(Long)); + resize(pos + static_cast<size_t>(sz) * sizeof(Long)); #ifdef ICE_BIG_ENDIAN const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Long) - 1; Byte* dest = &(*(b.begin() + pos)); @@ -433,7 +433,7 @@ Ice::OutputStream::write(const Long* begin, const Long* end) src += 2 * sizeof(Long); } #else - memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Long)); + memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), static_cast<size_t>(sz) * sizeof(Long)); #endif } } @@ -467,7 +467,7 @@ Ice::OutputStream::write(const Float* begin, const Float* end) if(sz > 0) { Container::size_type pos = b.size(); - resize(pos + sz * sizeof(Float)); + resize(pos + static_cast<size_t>(sz) * sizeof(Float)); #ifdef ICE_BIG_ENDIAN const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Float) - 1; Byte* dest = &(*(b.begin() + pos)); @@ -480,7 +480,7 @@ Ice::OutputStream::write(const Float* begin, const Float* end) src += 2 * sizeof(Float); } #else - memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Float)); + memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), static_cast<size_t>(sz) * sizeof(Float)); #endif } } @@ -522,7 +522,7 @@ Ice::OutputStream::write(const Double* begin, const Double* end) if(sz > 0) { Container::size_type pos = b.size(); - resize(pos + sz * sizeof(Double)); + resize(pos + static_cast<size_t>(sz) * sizeof(Double)); #ifdef ICE_BIG_ENDIAN const Byte* src = reinterpret_cast<const Byte*>(begin) + sizeof(Double) - 1; Byte* dest = &(*(b.begin() + pos)); @@ -539,7 +539,7 @@ Ice::OutputStream::write(const Double* begin, const Double* end) src += 2 * sizeof(Double); } #else - memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), sz * sizeof(Double)); + memcpy(&b[pos], reinterpret_cast<const Byte*>(begin), static_cast<size_t>(sz) * sizeof(Double)); #endif } } @@ -605,7 +605,7 @@ Ice::OutputStream::writeConverted(const char* vdata, size_t vsize) if(lastByte != b.end()) { - resize(lastByte - b.begin()); + resize(static_cast<size_t>(lastByte - b.begin())); } size_t lastIndex = b.size(); @@ -623,14 +623,14 @@ Ice::OutputStream::writeConverted(const char* vdata, size_t vsize) // Use memmove instead of memcpy since the source and destination typically overlap. // resize(b.size() + 4); - memmove(b.begin() + firstIndex + 4, b.begin() + firstIndex, actualSize); + memmove(b.begin() + firstIndex + 4, b.begin() + firstIndex, static_cast<size_t>(actualSize)); } else if(guessedSize > 254 && actualSize <= 254) { // // Move the UTF-8 sequence 4 bytes back // - memmove(b.begin() + firstIndex - 4, b.begin() + firstIndex, actualSize); + memmove(b.begin() + firstIndex - 4, b.begin() + firstIndex, static_cast<size_t>(actualSize)); resize(b.size() - 4); } @@ -700,7 +700,7 @@ Ice::OutputStream::write(const wstring& v) if(lastByte != b.end()) { - resize(lastByte - b.begin()); + resize(static_cast<size_t>(lastByte - b.begin())); } size_t lastIndex = b.size(); @@ -718,14 +718,14 @@ Ice::OutputStream::write(const wstring& v) // Use memmove instead of memcpy since the source and destination typically overlap. // resize(b.size() + 4); - memmove(b.begin() + firstIndex + 4, b.begin() + firstIndex, actualSize); + memmove(b.begin() + firstIndex + 4, b.begin() + firstIndex, static_cast<size_t>(actualSize)); } else if(guessedSize > 254 && actualSize <= 254) { // // Move the UTF-8 sequence 4 bytes back // - memmove(b.begin() + firstIndex - 4, b.begin() + firstIndex, actualSize); + memmove(b.begin() + firstIndex - 4, b.begin() + firstIndex, static_cast<size_t>(actualSize)); resize(b.size() - 4); } diff --git a/cpp/src/Ice/ProxyFactory.cpp b/cpp/src/Ice/ProxyFactory.cpp index e2ba9fdb923..db3ad7a5e63 100644 --- a/cpp/src/Ice/ProxyFactory.cpp +++ b/cpp/src/Ice/ProxyFactory.cpp @@ -237,7 +237,7 @@ IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, co } else { - interval = _retryIntervals[cnt - 1]; + interval = _retryIntervals[static_cast<size_t>(cnt - 1)]; } if(traceLevels->retry >= 1) diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index fcf016ac64a..7175eee5528 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -597,7 +597,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, InputStream* s) if(sz > 0) { - endpoints.reserve(sz); + endpoints.reserve(static_cast<size_t>(sz)); while(sz--) { EndpointIPtr endpoint = _instance->endpointFactoryManager()->read(s); diff --git a/cpp/src/Ice/Selector.cpp b/cpp/src/Ice/Selector.cpp index e76b8ad93f5..0070f93fb3f 100644 --- a/cpp/src/Ice/Selector.cpp +++ b/cpp/src/Ice/Selector.cpp @@ -612,7 +612,7 @@ Selector::finishSelect(vector<pair<EventHandler*, SocketOperation> >& handlers) ((ev.events & (EPOLLOUT | EPOLLERR)) ? SocketOperationWrite : SocketOperationNone)); #elif defined(ICE_USE_KQUEUE) - struct kevent& ev = _events[i]; + struct kevent& ev = _events[static_cast<size_t>(i)]; if(ev.flags & EV_ERROR) { Ice::Error out(_instance->initializationData().logger); @@ -822,11 +822,12 @@ Selector::updateSelector() // Check for errors, we ignore EINPROGRESS that started showing up with macOS Sierra // and which occurs when another thread removes the FD from the kqueue (see ICE-7419). // - if(_changes[i].flags & EV_ERROR && _changes[i].data != EINPROGRESS) + if(_changes[static_cast<size_t>(i)].flags & EV_ERROR && + _changes[static_cast<size_t>(i)].data != EINPROGRESS) { Ice::Error out(_instance->initializationData().logger); out << "error while updating selector:\n" - << IceUtilInternal::errorToString(static_cast<int>(_changes[i].data)); + << IceUtilInternal::errorToString(static_cast<int>(_changes[static_cast<size_t>(i)].data)); } } } diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp index 9642c46617a..1ec6cb4dbf3 100644 --- a/cpp/src/Ice/Service.cpp +++ b/cpp/src/Ice/Service.cpp @@ -1590,7 +1590,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa string message; while((rs = read(fds[0], &s, 16)) > 0) { - message.append(s, rs); + message.append(s, static_cast<size_t>(rs)); } if(argv[0]) @@ -1866,8 +1866,8 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa break; } } - len -= n; - pos += n; + len -= static_cast<size_t>(n); + pos += static_cast<size_t>(n); } close(fds[1]); } diff --git a/cpp/src/Ice/StreamSocket.cpp b/cpp/src/Ice/StreamSocket.cpp index f335736f8ca..e3b41088347 100755 --- a/cpp/src/Ice/StreamSocket.cpp +++ b/cpp/src/Ice/StreamSocket.cpp @@ -178,7 +178,7 @@ StreamSocket::read(Buffer& buf) { while(true) { - ssize_t ret = read(reinterpret_cast<char*>(&*buf.i), buf.b.end() - buf.i); + ssize_t ret = read(reinterpret_cast<char*>(&*buf.i), static_cast<size_t>(buf.b.end() - buf.i)); if(ret == 0) { return SocketOperationRead; @@ -191,7 +191,7 @@ StreamSocket::read(Buffer& buf) } } } - buf.i += read(reinterpret_cast<char*>(&*buf.i), buf.b.end() - buf.i); + buf.i += read(reinterpret_cast<char*>(&*buf.i), static_cast<size_t>(buf.b.end() - buf.i)); #endif return buf.i != buf.b.end() ? SocketOperationRead : SocketOperationNone; } @@ -204,7 +204,7 @@ StreamSocket::write(Buffer& buf) { while(true) { - ssize_t ret = write(reinterpret_cast<const char*>(&*buf.i), buf.b.end() - buf.i); + ssize_t ret = write(reinterpret_cast<const char*>(&*buf.i), static_cast<size_t>(buf.b.end() - buf.i)); if(ret == 0) { return SocketOperationWrite; @@ -217,7 +217,7 @@ StreamSocket::write(Buffer& buf) } } } - buf.i += write(reinterpret_cast<const char*>(&*buf.i), buf.b.end() - buf.i); + buf.i += write(reinterpret_cast<const char*>(&*buf.i), static_cast<size_t>(buf.b.end() - buf.i)); #endif return buf.i != buf.b.end() ? SocketOperationWrite : SocketOperationNone; } @@ -272,7 +272,7 @@ StreamSocket::read(char* buf, size_t length) buf += ret; read += ret; - length -= ret; + length -= static_cast<size_t>(ret); if(packetSize > length) { @@ -339,7 +339,7 @@ StreamSocket::write(const char* buf, size_t length) buf += ret; sent += ret; - length -= ret; + length -= static_cast<size_t>(ret); if(packetSize > length) { diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp index 5d6b64cc058..4407ca72da0 100755 --- a/cpp/src/Ice/UdpTransceiver.cpp +++ b/cpp/src/Ice/UdpTransceiver.cpp @@ -259,13 +259,21 @@ IceInternal::UdpTransceiver::read(Buffer& buf) assert(buf.i == buf.b.begin()); assert(_fd != INVALID_SOCKET); - const int packetSize = min(_maxPacketSize, _rcvSize - _udpOverhead); +#ifdef _WIN32 + int packetSize = min(_maxPacketSize, _rcvSize - _udpOverhead); +#else + const size_t packetSize = static_cast<size_t>(min(_maxPacketSize, _rcvSize - _udpOverhead)); +#endif buf.b.resize(packetSize); buf.i = buf.b.begin(); repeat: +#ifdef _WIN32 + int ret; +#else ssize_t ret; +#endif if(_state == StateConnected) { ret = ::recv(_fd, reinterpret_cast<char*>(&buf.b[0]), packetSize, 0); @@ -341,7 +349,7 @@ repeat: } } - buf.b.resize(ret); + buf.b.resize(static_cast<size_t>(ret)); buf.i = buf.b.end(); return SocketOperationNone; #endif diff --git a/cpp/src/Ice/WSTransceiver.cpp b/cpp/src/Ice/WSTransceiver.cpp index 07ef68538f6..725b07c7249 100644 --- a/cpp/src/Ice/WSTransceiver.cpp +++ b/cpp/src/Ice/WSTransceiver.cpp @@ -588,11 +588,11 @@ IceInternal::WSTransceiver::read(Buffer& buf) // no more than the payload length. The remaining of the buffer will be // sent over in another frame. // - size_t readSz = _readPayloadLength - (buf.i - _readStart); // Already read + size_t readSz = _readPayloadLength - static_cast<size_t>(buf.i - _readStart); // Already read if(static_cast<size_t>(buf.b.end() - buf.i) > readSz) { size_t size = buf.b.size(); - buf.b.resize(buf.i - buf.b.begin() + readSz); + buf.b.resize(static_cast<size_t>(buf.i - buf.b.begin()) + readSz); s = _delegate->read(buf); buf.b.resize(size); } @@ -1394,7 +1394,7 @@ IceInternal::WSTransceiver::preRead(Buffer& buf) return false; } - size_t n = min(_readBuffer.i - _readI, buf.b.end() - buf.i); + size_t n = min(static_cast<size_t>(_readBuffer.i - _readI), static_cast<size_t>(buf.b.end() - buf.i)); if(n > _readPayloadLength) { @@ -1435,13 +1435,13 @@ IceInternal::WSTransceiver::postRead(Buffer& buf) // Unmask the data we just read. // IceInternal::Buffer::Container::iterator p = _readStart; - for(size_t n = _readStart - _readFrameStart; p < buf.i; ++p, ++n) + for(size_t n = static_cast<size_t>(_readStart - _readFrameStart); p < buf.i; ++p, ++n) { *p ^= _readMask[n % 4]; } } - _readPayloadLength -= buf.i - _readStart; + _readPayloadLength -= static_cast<size_t>(buf.i - _readStart); _readStart = buf.i; if(_readPayloadLength == 0) { @@ -1474,7 +1474,7 @@ IceInternal::WSTransceiver::preWrite(Buffer& buf) { prepareWriteHeader(OP_PING, 0); // Don't send any payload - _writeBuffer.b.resize(_writeBuffer.i - _writeBuffer.b.begin()); + _writeBuffer.b.resize(static_cast<size_t>(_writeBuffer.i - _writeBuffer.b.begin())); _writeState = WriteStateControlFrame; _writeBuffer.i = _writeBuffer.b.begin(); } @@ -1483,7 +1483,7 @@ IceInternal::WSTransceiver::preWrite(Buffer& buf) prepareWriteHeader(OP_PONG, _pingPayload.size()); if(_pingPayload.size() > static_cast<size_t>(_writeBuffer.b.end() - _writeBuffer.i)) { - size_t pos = _writeBuffer.i - _writeBuffer.b.begin(); + size_t pos = static_cast<size_t>(_writeBuffer.i - _writeBuffer.b.begin()); _writeBuffer.b.resize(pos + _pingPayload.size()); _writeBuffer.i = _writeBuffer.b.begin() + pos; } @@ -1491,7 +1491,7 @@ IceInternal::WSTransceiver::preWrite(Buffer& buf) _writeBuffer.i += _pingPayload.size(); _pingPayload.clear(); - _writeBuffer.b.resize(_writeBuffer.i - _writeBuffer.b.begin()); + _writeBuffer.b.resize(static_cast<size_t>(_writeBuffer.i - _writeBuffer.b.begin())); _writeState = WriteStateControlFrame; _writeBuffer.i = _writeBuffer.b.begin(); } @@ -1513,7 +1513,7 @@ IceInternal::WSTransceiver::preWrite(Buffer& buf) } _writeState = WriteStateControlFrame; - _writeBuffer.b.resize(_writeBuffer.i - _writeBuffer.b.begin()); + _writeBuffer.b.resize(static_cast<size_t>(_writeBuffer.i - _writeBuffer.b.begin())); _writeBuffer.i = _writeBuffer.b.begin(); } else @@ -1543,7 +1543,7 @@ IceInternal::WSTransceiver::preWrite(Buffer& buf) _writeBuffer.i = _writeBuffer.b.begin(); } - size_t n = buf.i - buf.b.begin(); + size_t n = static_cast<size_t>(buf.i - buf.b.begin()); for(; n < buf.b.size() && _writeBuffer.i < _writeBuffer.b.end(); ++_writeBuffer.i, ++n) { *_writeBuffer.i = buf.b[n] ^ _writeMask[n % 4]; @@ -1551,20 +1551,21 @@ IceInternal::WSTransceiver::preWrite(Buffer& buf) _writePayloadLength = n; if(_writeBuffer.i < _writeBuffer.b.end()) { - _writeBuffer.b.resize(_writeBuffer.i - _writeBuffer.b.begin()); + _writeBuffer.b.resize(static_cast<size_t>(_writeBuffer.i - _writeBuffer.b.begin())); } _writeBuffer.i = _writeBuffer.b.begin(); } else if(_writePayloadLength == 0) { - size_t n = min(_writeBuffer.b.end() - _writeBuffer.i, buf.b.end() - buf.i); + size_t n = min(static_cast<size_t>(_writeBuffer.b.end() - _writeBuffer.i), + static_cast<size_t>(buf.b.end() - buf.i)); memcpy(_writeBuffer.i, buf.i, n); _writeBuffer.i += n; buf.i += n; _writePayloadLength = n; if(_writeBuffer.i < _writeBuffer.b.end()) { - _writeBuffer.b.resize(_writeBuffer.i - _writeBuffer.b.begin()); + _writeBuffer.b.resize(static_cast<size_t>(_writeBuffer.i - _writeBuffer.b.begin())); } _writeBuffer.i = _writeBuffer.b.begin(); } @@ -1670,7 +1671,7 @@ IceInternal::WSTransceiver::readBuffered(IceInternal::Buffer::Container::size_ty } else { - IceInternal::Buffer::Container::size_type available = _readBuffer.i - _readI; + size_t available = static_cast<size_t>(_readBuffer.i - _readI); if(available < sz) { if(_readI != &_readBuffer.b[0]) @@ -1728,7 +1729,7 @@ IceInternal::WSTransceiver::prepareWriteHeader(Byte opCode, IceInternal::Buffer: // Use an extra 64 bits to encode the payload length. // *_writeBuffer.i++ = static_cast<Byte>(127); - ice_htonll(payloadLength, _writeBuffer.i); + ice_htonll(static_cast<Long>(payloadLength), _writeBuffer.i); _writeBuffer.i += 8; } |