Skip to content

Commit d8c2300

Browse files
authored
Fix shift overflow bug in ++ and -- (#85)
1 parent 892df22 commit d8c2300

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/FixedPoints/SFixedMemberFunctions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ constexpr SFixed<Integer, Fraction> SFixed<Integer, Fraction>::operator -() cons
221221
template< unsigned Integer, unsigned Fraction >
222222
SFixed<Integer, Fraction> & SFixed<Integer, Fraction>::operator ++()
223223
{
224-
this->value += (1 << FractionSize);
224+
this->value += (static_cast<InternalType>(1) << FractionSize);
225225
return *this;
226226
}
227227

228228
template< unsigned Integer, unsigned Fraction >
229229
SFixed<Integer, Fraction> & SFixed<Integer, Fraction>::operator --()
230230
{
231-
this->value -= (1 << FractionSize);
231+
this->value -= (static_cast<InternalType>(1) << FractionSize);
232232
return *this;
233233
}
234234

src/FixedPoints/UFixedMemberFunctions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ constexpr UFixed<Integer, Fraction> UFixed<Integer, Fraction>::fromInternal(cons
206206
template< unsigned Integer, unsigned Fraction >
207207
UFixed<Integer, Fraction> & UFixed<Integer, Fraction>::operator ++()
208208
{
209-
this->value += (1 << FractionSize);
209+
this->value += (static_cast<InternalType>(1) << FractionSize);
210210
return *this;
211211
}
212212

213213
template< unsigned Integer, unsigned Fraction >
214214
UFixed<Integer, Fraction> & UFixed<Integer, Fraction>::operator --()
215215
{
216-
this->value -= (1 << FractionSize);
216+
this->value -= (static_cast<InternalType>(1) << FractionSize);
217217
return *this;
218218
}
219219

0 commit comments

Comments
 (0)