Skip to content
Snippets Groups Projects
Commit a81755d1 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

fix use of uninitialized value in vector bool operator >>

parent d60d4895
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -192,20 +192,18 @@ ext::vector < bool, Ts ... > & operator <<= ( ext::vector < bool, Ts ... > & A,
return A;
 
// shift by the rest dist
{
vectorBoolInternalType bits1 { };
vectorBoolInternalType bits2 { };
vectorBoolInternalType bits1 { };
vectorBoolInternalType bits2 { };
 
// it might be more clear to iterate from the begining. However this is working nicely
auto itA = A.begin ( );
// it might be more clear to iterate from the begining. However this is working nicely
auto itA = A.begin ( );
 
while ( itA < A.end ( ) ) {
bits2 = * ( itA._M_p );
* ( itA._M_p ) = * ( itA._M_p ) << distWithin | bits1 >> backDist;
bits1 = bits2;
while ( itA < A.end ( ) ) {
bits2 = * ( itA._M_p );
* ( itA._M_p ) = * ( itA._M_p ) << distWithin | bits1 >> backDist;
bits1 = bits2;
 
itA._M_p ++;
}
itA._M_p ++;
}
 
return A;
......@@ -227,6 +225,10 @@ ext::vector < bool, Ts ... > & operator >>= ( ext::vector < bool, Ts ... > & A,
size_t sizeWithin = A.size ( ) % vectorBoolInternalTypeInBits;
size_t backDist = vectorBoolInternalTypeInBits - distWithin;
 
// upper part of the last word in the ext::vector can contain some garbage so it needs to be cleared
if ( sizeWithin != 0 )
* ( ( A.end ( ) - 1 )._M_p ) &= getMask ( sizeWithin );
// shift blocks if needed
if ( distBlocks ) {
auto itA = A.begin ( );
......@@ -244,25 +246,19 @@ ext::vector < bool, Ts ... > & operator >>= ( ext::vector < bool, Ts ... > & A,
return A;
 
// shift by the rest dist
{
vectorBoolInternalType bits1 { };
vectorBoolInternalType bits2 { };
vectorBoolInternalType bits1 { };
vectorBoolInternalType bits2 { };
 
// it might be more clear to iterate from the begining. However this is working nicely
auto itAReverse = A.end ( ) - 1;
// upper part of the last word in the ext::vector can contain some garbage so it needs to be cleared
if ( sizeWithin != 0 )
* ( itAReverse._M_p ) &= getMask ( sizeWithin );
// it might be more clear to iterate from the begining. However this is working nicely
auto itAReverse = A.end ( ) - 1;
 
// simulate behavior of reverse iterator
while ( itAReverse >= A.begin ( ) ) {
bits2 = * ( itAReverse._M_p );
* ( itAReverse._M_p ) = * ( itAReverse._M_p ) >> distWithin | bits1 << backDist;
bits1 = bits2;
// simulate behavior of reverse iterator
while ( itAReverse >= A.begin ( ) ) {
bits2 = * ( itAReverse._M_p );
* ( itAReverse._M_p ) = * ( itAReverse._M_p ) >> distWithin | bits1 << backDist;
bits1 = bits2;
 
itAReverse._M_p --;
}
itAReverse._M_p --;
}
 
return A;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment