From d8c2300585072c58c6d7c80efaed10b661070e00 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Fri, 26 Mar 2021 12:21:08 +0000 Subject: [PATCH] Fix shift overflow bug in ++ and -- (#85) --- src/FixedPoints/SFixedMemberFunctions.h | 4 ++-- src/FixedPoints/UFixedMemberFunctions.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/FixedPoints/SFixedMemberFunctions.h b/src/FixedPoints/SFixedMemberFunctions.h index 3a0e7c7..9d1268b 100644 --- a/src/FixedPoints/SFixedMemberFunctions.h +++ b/src/FixedPoints/SFixedMemberFunctions.h @@ -221,14 +221,14 @@ constexpr SFixed SFixed::operator -() cons template< unsigned Integer, unsigned Fraction > SFixed & SFixed::operator ++() { - this->value += (1 << FractionSize); + this->value += (static_cast(1) << FractionSize); return *this; } template< unsigned Integer, unsigned Fraction > SFixed & SFixed::operator --() { - this->value -= (1 << FractionSize); + this->value -= (static_cast(1) << FractionSize); return *this; } diff --git a/src/FixedPoints/UFixedMemberFunctions.h b/src/FixedPoints/UFixedMemberFunctions.h index 4316cff..2540b9f 100644 --- a/src/FixedPoints/UFixedMemberFunctions.h +++ b/src/FixedPoints/UFixedMemberFunctions.h @@ -206,14 +206,14 @@ constexpr UFixed UFixed::fromInternal(cons template< unsigned Integer, unsigned Fraction > UFixed & UFixed::operator ++() { - this->value += (1 << FractionSize); + this->value += (static_cast(1) << FractionSize); return *this; } template< unsigned Integer, unsigned Fraction > UFixed & UFixed::operator --() { - this->value -= (1 << FractionSize); + this->value -= (static_cast(1) << FractionSize); return *this; }