uint128: Check for large shift count before truncating in << and >>
- Correctly handle very large shift counts - uint128(1) << (uint64_t(1) << 32) should now be 0 as expected
This commit is contained in:
parent
ac197311ca
commit
4b8c211629
1 changed files with 9 additions and 8 deletions
|
|
@ -150,15 +150,14 @@ namespace fc
|
||||||
|
|
||||||
uint128& uint128::operator<<=(const uint128& rhs)
|
uint128& uint128::operator<<=(const uint128& rhs)
|
||||||
{
|
{
|
||||||
unsigned int n = rhs.to_integer();
|
if(rhs >= 128)
|
||||||
|
|
||||||
if(n >= 128)
|
|
||||||
{
|
{
|
||||||
hi = 0;
|
hi = 0;
|
||||||
lo = 0;
|
lo = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
unsigned int n = rhs.to_integer();
|
||||||
const unsigned int halfsize = 128 / 2;
|
const unsigned int halfsize = 128 / 2;
|
||||||
|
|
||||||
if(n >= halfsize){
|
if(n >= halfsize){
|
||||||
|
|
@ -186,12 +185,14 @@ namespace fc
|
||||||
|
|
||||||
uint128 & uint128::operator>>=(const uint128& rhs)
|
uint128 & uint128::operator>>=(const uint128& rhs)
|
||||||
{
|
{
|
||||||
unsigned int n = rhs.to_integer();
|
if(rhs >= 128)
|
||||||
|
{
|
||||||
if(n >= 128) {
|
|
||||||
hi = 0;
|
hi = 0;
|
||||||
lo = 0;
|
lo = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned int n = rhs.to_integer();
|
||||||
const unsigned int halfsize = 128 / 2;
|
const unsigned int halfsize = 128 / 2;
|
||||||
|
|
||||||
if(n >= halfsize) {
|
if(n >= halfsize) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue