Check -INT_MIN case in safe.hpp negate operator
This commit is contained in:
parent
e71ea52075
commit
b393ddc1da
1 changed files with 8 additions and 3 deletions
|
|
@ -33,7 +33,12 @@ namespace fc {
|
||||||
}
|
}
|
||||||
safe& operator *= ( T v ) { value *= v; return *this; }
|
safe& operator *= ( T v ) { value *= v; return *this; }
|
||||||
safe& operator -= ( const safe& b ) { return *this += safe(-b.value); }
|
safe& operator -= ( const safe& b ) { return *this += safe(-b.value); }
|
||||||
safe operator -()const{ return safe(-value); }
|
safe operator -()const
|
||||||
|
{
|
||||||
|
if( value == std::numeric_limits<T>::min() )
|
||||||
|
FC_CAPTURE_AND_THROW( overflow_exception, (value) );
|
||||||
|
return safe(-value);
|
||||||
|
}
|
||||||
|
|
||||||
friend safe operator - ( const safe& a, const safe& b )
|
friend safe operator - ( const safe& a, const safe& b )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue