From 3993102e880f2a31b6fef9484b8527a58e850744 Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Mon, 29 Dec 2014 23:53:08 +1000 Subject: [PATCH] Fix -Wtype-limits warnings and remove disabling of -Wtype-limits --- src/CMakeLists.txt | 5 ----- src/connection.cpp | 19 ++++++++++--------- src/map.cpp | 6 +++++- src/serialization.h | 4 +++- src/server.cpp | 2 +- src/tile.cpp | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 47fa5e216..2fc30b842 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -643,11 +643,6 @@ else() if(HAS_UNUSED_BUT_SET_VARIABLE_WARNING) set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-unused-but-set-variable") endif(HAS_UNUSED_BUT_SET_VARIABLE_WARNING) - - CHECK_CXX_COMPILER_FLAG("-Wno-type-limits" HAS_TYPE_LIMITS_WARNING) - if(HAS_TYPE_LIMITS_WARNING) - set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-type-limits") - endif(HAS_TYPE_LIMITS_WARNING) endif() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") diff --git a/src/connection.cpp b/src/connection.cpp index a9f1d5457..02ca91a91 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -2334,6 +2334,11 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, u8 type = readU8(&(packetdata[0])); + if (MAX_UDP_PEERS <= 65535 && peer_id >= MAX_UDP_PEERS) { + errorstream << "Something is wrong with peer_id" << std::endl; + assert(0); + } + if(type == TYPE_CONTROL) { if(packetdata.getSize() < 2) @@ -2341,8 +2346,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, u8 controltype = readU8(&(packetdata[1])); - if( (controltype == CONTROLTYPE_ACK) - && (peer_id <= MAX_UDP_PEERS)) + if(controltype == CONTROLTYPE_ACK) { assert(channel != 0); if(packetdata.getSize() < 4) @@ -2399,8 +2403,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, } throw ProcessedSilentlyException("Got an ACK"); } - else if((controltype == CONTROLTYPE_SET_PEER_ID) - && (peer_id <= MAX_UDP_PEERS)) + else if(controltype == CONTROLTYPE_SET_PEER_ID) { // Got a packet to set our peer id if(packetdata.getSize() < 4) @@ -2432,8 +2435,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, throw ProcessedSilentlyException("Got a SET_PEER_ID"); } - else if((controltype == CONTROLTYPE_PING) - && (peer_id <= MAX_UDP_PEERS)) + else if(controltype == CONTROLTYPE_PING) { // Just ignore it, the incoming data already reset // the timeout counter @@ -2455,8 +2457,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, throw ProcessedSilentlyException("Got a DISCO"); } - else if((controltype == CONTROLTYPE_ENABLE_BIG_SEND_WINDOW) - && (peer_id <= MAX_UDP_PEERS)) + else if(controltype == CONTROLTYPE_ENABLE_BIG_SEND_WINDOW) { dynamic_cast(&peer)->setNonLegacyPeer(); throw ProcessedSilentlyException("Got non legacy control"); @@ -2514,7 +2515,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, //TODO throw some error } } - else if((peer_id <= MAX_UDP_PEERS) && (type == TYPE_RELIABLE)) + else if(type == TYPE_RELIABLE) { assert(channel != 0); // Recursive reliable packets not allowed diff --git a/src/map.cpp b/src/map.cpp index 7a58c90c7..1c1cd7c28 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1766,7 +1766,11 @@ void Map::transformLiquids(std::map & modified_blocks) content_t new_node_content; s8 new_node_level = -1; s8 max_node_level = -1; - u8 range = rangelim(nodemgr->get(liquid_kind).liquid_range, 0, LIQUID_LEVEL_MAX+1); + + u8 range = nodemgr->get(liquid_kind).liquid_range; + if (range > LIQUID_LEVEL_MAX+1) + range = LIQUID_LEVEL_MAX+1; + if ((num_sources >= 2 && nodemgr->get(liquid_kind).liquid_renewable) || liquid_type == LIQUID_SOURCE) { // liquid_kind will be set to either the flowing alternative of the node (if it's a liquid) // or the flowing alternative of the first of the surrounding sources (if it's air), so diff --git a/src/serialization.h b/src/serialization.h index 41a505455..caa1a66da 100644 --- a/src/serialization.h +++ b/src/serialization.h @@ -72,7 +72,9 @@ with this program; if not, write to the Free Software Foundation, Inc., // Lowest supported serialization version #define SER_FMT_VER_LOWEST 0 -#define ser_ver_supported(v) (v >= SER_FMT_VER_LOWEST && v <= SER_FMT_VER_HIGHEST_READ) +inline bool ser_ver_supported(s32 v) { + return v >= SER_FMT_VER_LOWEST && v <= SER_FMT_VER_HIGHEST_READ; +} /* Misc. serialization functions diff --git a/src/server.cpp b/src/server.cpp index 161aaafc7..a52cd639d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1361,7 +1361,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) u8 client_max = data[2]; u8 our_max = SER_FMT_VER_HIGHEST_READ; // Use the highest version supported by both - u8 deployed = std::min(client_max, our_max); + int deployed = std::min(client_max, our_max); // If it's lower than the lowest supported, give up. if(deployed < SER_FMT_VER_LOWEST) deployed = SER_FMT_VER_INVALID; diff --git a/src/tile.cpp b/src/tile.cpp index fa2f4c84e..e7e37a4fe 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -1859,7 +1859,7 @@ void imageTransform(u32 transform, video::IImage *src, video::IImage *dst) core::dimension2d dstdim = dst->getDimension(); assert(dstdim == imageTransformDimension(transform, srcdim)); - assert(transform >= 0 && transform <= 7); + assert(transform <= 7); /* Compute the transformation from source coordinates (sx,sy)