LSET: Prevent assertion in MSW when size is not a multiple of 4

This commit is contained in:
Jon Evans 2019-12-25 11:34:12 -05:00
parent a12b803af5
commit 2ea565473f
1 changed files with 8 additions and 5 deletions

View File

@ -286,15 +286,18 @@ std::string LSET::FmtHex() const
static const char hex[] = "0123456789abcdef"; static const char hex[] = "0123456789abcdef";
int nibble_count = ( size() + 3 ) / 4; unsigned nibble_count = ( size() + 3 ) / 4;
for( int nibble=0; nibble<nibble_count; ++nibble ) for( unsigned nibble = 0; nibble < nibble_count; ++nibble )
{ {
unsigned ndx = 0; unsigned ndx = 0;
// test 4 consecutive bits and set ndx to 0-15: // test 4 consecutive bits and set ndx to 0-15:
for( int nibble_bit=0; nibble_bit<4; ++nibble_bit ) for( unsigned nibble_bit = 0; nibble_bit < 4; ++nibble_bit )
{ {
if( ( nibble_bit + nibble * 4 ) >= size() )
break;
if( (*this)[nibble_bit + nibble * 4] ) if( (*this)[nibble_bit + nibble * 4] )
ndx |= ( 1 << nibble_bit ); ndx |= ( 1 << nibble_bit );
} }