More refactoring reported by SonarLint

This commit is contained in:
Serge Lamikhov-Center 2022-09-16 20:47:15 +03:00
parent b996977925
commit b57b08409b
4 changed files with 32 additions and 28 deletions

View File

@ -43,7 +43,7 @@ template <class S> class modinfo_section_accessor_template
//------------------------------------------------------------------------------
bool
get_attribute( Elf_Word no, std::string& field, std::string& value ) const
get_attribute( Elf_Word no, const std::string& field, const std::string& value ) const
{
if ( no < content.size() ) {
field = content[no].first;

View File

@ -356,34 +356,36 @@ template <class S> class symbol_section_accessor_template
( (T)1 << ( hash % ( 8 * sizeof( T ) ) ) ) |
( (T)1 << ( ( hash >> bloom_shift ) % ( 8 * sizeof( T ) ) ) );
if ( ( convertor( bloom_filter[bloom_index] ) & bloom_bits ) ==
bloom_bits ) {
uint32_t bucket = hash % nbuckets;
auto* buckets =
(uint32_t*)( hash_section->get_data() + 4 * sizeof( uint32_t ) +
bloom_size * sizeof( T ) );
auto* chains =
(uint32_t*)( hash_section->get_data() + 4 * sizeof( uint32_t ) +
bloom_size * sizeof( T ) +
nbuckets * sizeof( uint32_t ) );
if ( ( convertor( bloom_filter[bloom_index] ) & bloom_bits ) !=
bloom_bits )
return ret;
if ( convertor( buckets[bucket] ) >= symoffset ) {
uint32_t chain_index = convertor( buckets[bucket] ) - symoffset;
uint32_t chain_hash = convertor( chains[chain_index] );
std::string symname;
while ( true ) {
if ( ( chain_hash >> 1 ) == ( hash >> 1 ) &&
get_symbol( chain_index + symoffset, symname, value,
size, bind, type, section_index, other ) &&
name == symname ) {
ret = true;
break;
}
uint32_t bucket = hash % nbuckets;
auto* buckets =
(uint32_t*)( hash_section->get_data() + 4 * sizeof( uint32_t ) +
bloom_size * sizeof( T ) );
auto* chains =
(uint32_t*)( hash_section->get_data() + 4 * sizeof( uint32_t ) +
bloom_size * sizeof( T ) +
nbuckets * sizeof( uint32_t ) );
if ( chain_hash & 1 )
break;
chain_hash = convertor( chains[++chain_index] );
if ( convertor( buckets[bucket] ) >= symoffset ) {
uint32_t chain_index = convertor( buckets[bucket] ) - symoffset;
uint32_t chain_hash = convertor( chains[chain_index] );
std::string symname;
while ( true ) {
if ( ( chain_hash >> 1 ) == ( hash >> 1 ) &&
get_symbol( chain_index + symoffset, symname, value, size,
bind, type, section_index, other ) &&
name == symname ) {
ret = true;
break;
}
if ( chain_hash & 1 )
break;
chain_hash = convertor( chains[++chain_index] );
}
}

View File

@ -209,7 +209,8 @@ class address_translator
//------------------------------------------------------------------------------
inline uint32_t elf_hash( const unsigned char* name )
{
uint32_t h = 0, g = 0;
uint32_t h = 0;
uint32_t g = 0;
while ( *name != '\0' ) {
h = ( h << 4 ) + *name++;
g = h & 0xf0000000;

View File

@ -30,7 +30,8 @@ template <class S> class versym_section_accessor_template
{
public:
//------------------------------------------------------------------------------
versym_section_accessor_template( S* section ) : versym_section( section )
explicit versym_section_accessor_template( S* section )
: versym_section( section )
{
if ( section ) {
entries_num = decltype( entries_num )( section->get_size() /