diff --git a/src/Anon.cc b/src/Anon.cc index facc5dbbb2..fbcbc00a1a 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -259,6 +259,10 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::make_peer(ipaddr32_t a, Node* n) // swivel is first bit 'a' and 'old->input' differ. int swivel = bi_ffs(a ^ n->input); + // Shifting by more than 31 bits below results in undefined behavior. + // This shouldn't be possible, but check anyways. + ASSERT(swivel > 0); + // bitvalue is the value of that bit of 'a'. int bitvalue = (a >> (32 - swivel)) & 1; @@ -305,6 +309,10 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::find_node(ipaddr32_t a) { // differ. int swivel = bi_ffs(n->child[0]->input ^ n->child[1]->input); + // Shifting by more than 31 bits below results in undefined behavior. + // This shouldn't be possible, but check anyways. + ASSERT(swivel > 0); + if ( bi_ffs(a ^ n->input) < swivel ) // Input differs earlier. n = make_peer(a, n); diff --git a/src/Val.cc b/src/Val.cc index 35b088870c..fe87c42aa0 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -751,7 +751,7 @@ IPAddr SubNetVal::Mask() const { for ( w = subnet_val->Length(); w >= 32; w -= 32 ) *(mp++) = 0xffffffff; - *mp = ~((1 << (32 - w)) - 1); + *mp = ~((static_cast(1) << (32 - w)) - 1); while ( ++mp < m + 4 ) *mp = 0;