Increased the warning level
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Wed, 13 Apr 2011 08:48:29 +0000 (10:48 +0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Wed, 13 Apr 2011 08:48:29 +0000 (10:48 +0200)
- included -pedantic, -Wshadow, -Wcast-qual and -Wconversion warnings
- fixed some warnings regarding lost of precision from conversions
- asserted that intermediate products from arithmetic operations fall within certain range

CMakeLists.txt
src/host/boostpinger.cpp
src/icmp/icmpmessagepayload.cpp
src/icmp/ipv4header.cpp

index 124e950..d2a2cb3 100644 (file)
@@ -24,7 +24,9 @@ set(CMAKE_BUILD_TYPE Debug)
 
 # compiler: add definitions and arguments to the compiler
 add_definitions(
-    -Werror -Wall -Wextra -Weffc++ -O2 -DVERSION_STRING=${VERSION}
+    -Wall -Wextra -Weffc++ -Wshadow -Wcast-qual -Wconversion -pedantic
+    -Werror -O2
+    -DVERSION_STRING=${VERSION}
     -DPROJECT_NAME=\"${PROJECT_NAME}\"
 )
 
index c8fcb1f..9f7306d 100644 (file)
@@ -5,6 +5,8 @@
 #include <ostream>
 
 #include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
 
 #include "icmp/icmpchecksumcalculator.h"
 #include "icmp/icmpdata.h"
@@ -18,6 +20,7 @@ using boost::asio::const_buffers_1;
 using boost::asio::io_service;
 using boost::asio::ip::address;
 using boost::asio::ip::icmp;
+using boost::date_time::time_resolution_traits_adapted64_impl;
 using boost::posix_time::microsec_clock;
 using boost::posix_time::ptime;
 using boost::posix_time::seconds;
@@ -281,7 +284,8 @@ void BoostPinger::print_echo_reply(
     uint16_t sequence_number = icmp_hdr.get_sequence_number();
     int ttl = ipv4_hdr.get_time_to_live();
     ptime now = microsec_clock::universal_time();
-    int elapsed_time = (now - TimeSent).total_milliseconds();
+    time_resolution_traits_adapted64_impl::int_type elapsed_time =
+            (now - TimeSent).total_milliseconds();
 
     cout << bytes_received << " bytes "
          << "from " << remote_address
index e6e8391..dbe0b17 100644 (file)
@@ -1,5 +1,7 @@
 #include "icmp/icmpmessagepayload.h"
 
+#include <limits>
+
 #include <boost/assert.hpp>
 
 using namespace std;
@@ -37,7 +39,11 @@ uint16_t IcmpMessagePayload::decode(
         const int right_byte
 ) const
 {
-    return ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ];
+    int value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ];
+
+    BOOST_ASSERT( ( 0 <= value ) && ( value <= numeric_limits<uint16_t>::max() ) );
+
+    return static_cast<uint16_t> ( value );
 }
 
 void IcmpMessagePayload::encode(
index 1e9ddf4..205b364 100644 (file)
@@ -1,5 +1,7 @@
 #include "icmp/ipv4header.h"
 
+#include <limits>
+
 using namespace std;
 using boost::asio::ip::address_v4;
 
@@ -21,7 +23,7 @@ uint8_t Ipv4Header::get_version() const
 
 uint16_t Ipv4Header::get_header_length() const
 {
-    return ( Payload[ 0 ] & 0xF ) * 4;
+    return static_cast<uint16_t> ( (Payload[ 0 ] & 0xF) * 4 );
 }
 
 uint8_t Ipv4Header::get_type_of_service() const
@@ -124,5 +126,9 @@ istream &operator>>(
 
 uint16_t Ipv4Header::decode( int left_byte, int right_byte ) const
 {
-    return ( (Payload[ left_byte ] << 8) + Payload[ right_byte ] );
+    int value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ];
+
+    BOOST_ASSERT( ( 0 <= value ) && ( value <= numeric_limits<uint16_t>::max() ) );
+
+    return static_cast<uint16_t> ( value );
 }