From b393ddc1da900fa421a0999fa57190ca2c013b91 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Mon, 2 Mar 2015 09:50:31 -0500 Subject: [PATCH] Check -INT_MIN case in safe.hpp negate operator --- include/fc/safe.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/fc/safe.hpp b/include/fc/safe.hpp index 4a5eca8..ec46063 100644 --- a/include/fc/safe.hpp +++ b/include/fc/safe.hpp @@ -10,7 +10,7 @@ namespace fc { * throw an exception on overflow conditions. */ template - struct safe + struct safe { template safe( O o ):value(o){} @@ -33,7 +33,12 @@ namespace fc { } safe& operator *= ( T v ) { value *= v; return *this; } safe& operator -= ( const safe& b ) { return *this += safe(-b.value); } - safe operator -()const{ return safe(-value); } + safe operator -()const + { + if( value == std::numeric_limits::min() ) + FC_CAPTURE_AND_THROW( overflow_exception, (value) ); + return safe(-value); + } friend safe operator - ( const safe& a, const safe& b ) { @@ -63,6 +68,6 @@ namespace fc { T value = 0; }; -} +} FC_REFLECT_TEMPLATE( (typename T), safe, (value) )