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 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() ) { if ( no < content.size() ) {
field = content[no].first; 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 % ( 8 * sizeof( T ) ) ) ) |
( (T)1 << ( ( hash >> bloom_shift ) % ( 8 * sizeof( T ) ) ) ); ( (T)1 << ( ( hash >> bloom_shift ) % ( 8 * sizeof( T ) ) ) );
if ( ( convertor( bloom_filter[bloom_index] ) & bloom_bits ) == if ( ( convertor( bloom_filter[bloom_index] ) & bloom_bits ) !=
bloom_bits ) { bloom_bits )
uint32_t bucket = hash % nbuckets; return ret;
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( buckets[bucket] ) >= symoffset ) { uint32_t bucket = hash % nbuckets;
uint32_t chain_index = convertor( buckets[bucket] ) - symoffset; auto* buckets =
uint32_t chain_hash = convertor( chains[chain_index] ); (uint32_t*)( hash_section->get_data() + 4 * sizeof( uint32_t ) +
std::string symname; bloom_size * sizeof( T ) );
while ( true ) { auto* chains =
if ( ( chain_hash >> 1 ) == ( hash >> 1 ) && (uint32_t*)( hash_section->get_data() + 4 * sizeof( uint32_t ) +
get_symbol( chain_index + symoffset, symname, value, bloom_size * sizeof( T ) +
size, bind, type, section_index, other ) && nbuckets * sizeof( uint32_t ) );
name == symname ) {
ret = true;
break;
}
if ( chain_hash & 1 ) if ( convertor( buckets[bucket] ) >= symoffset ) {
break; uint32_t chain_index = convertor( buckets[bucket] ) - symoffset;
chain_hash = convertor( chains[++chain_index] ); 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 ) 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' ) { while ( *name != '\0' ) {
h = ( h << 4 ) + *name++; h = ( h << 4 ) + *name++;
g = h & 0xf0000000; g = h & 0xf0000000;

View File

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