From 3ab2cfadaf52302560de3ae2177119dbcc552d35 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Tue, 19 Apr 2011 14:00:25 +0200 Subject: [PATCH] The speed_up method could set the Interval to zero, which is a bug. - also added asserts to harden the code and ensure the Interval will never become an invalid value. --- src/host/pinginterval.h | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-) diff --git a/src/host/pinginterval.h b/src/host/pinginterval.h index f76272c..6e0a480 100644 --- a/src/host/pinginterval.h +++ b/src/host/pinginterval.h @@ -1,6 +1,8 @@ #ifndef PINGINTERVAL_H #define PINGINTERVAL_H +#include + //----------------------------------------------------------------------------- // PingInterval //----------------------------------------------------------------------------- @@ -39,6 +41,7 @@ template OriginalInterval( interval ), Interval( interval ) { + BOOST_ASSERT( 0 < interval ); } template @@ -49,6 +52,8 @@ template template PingInterval::operator T() { + BOOST_ASSERT( 0 < Interval ); + return Interval; } @@ -56,13 +61,26 @@ template void PingInterval::back_to_original() { Interval = OriginalInterval; + + BOOST_ASSERT( 0 < Interval ); } template void PingInterval::speed_up() { + BOOST_ASSERT( 0 < Interval ); + if ( can_speed_up() ) + { Interval = Interval / 2; + } + + if ( Interval < 1 ) + { + Interval = 1; + } + + BOOST_ASSERT( 0 < Interval ); } template @@ -70,7 +88,7 @@ template { T half_original = OriginalInterval / 2; - return (Interval > half_original); + return ( Interval > half_original ); } -- 1.7.1