Apply advices given by clang-tidy

This commit is contained in:
Serge Lamikhov-Center 2022-09-28 20:09:33 +03:00
parent 19bfbd5825
commit 619c9b6884
3 changed files with 33 additions and 30 deletions

View File

@ -294,10 +294,10 @@ template <class S> class relocation_section_accessor_template
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void swap_symbols( Elf_Xword first, Elf_Xword second ) void swap_symbols( Elf_Xword first, Elf_Xword second )
{ {
Elf64_Addr offset; Elf64_Addr offset = 0;
Elf_Word symbol; Elf_Word symbol = 0;
unsigned rtype; unsigned rtype = 0;
Elf_Sxword addend; Elf_Sxword addend = 0;
for ( Elf_Word i = 0; i < get_entries_num(); i++ ) { for ( Elf_Word i = 0; i < get_entries_num(); i++ ) {
get_entry( i, offset, symbol, rtype, addend ); get_entry( i, offset, symbol, rtype, addend );
if ( symbol == first ) { if ( symbol == first ) {
@ -447,7 +447,7 @@ template <class S> class relocation_section_accessor_template
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
private: private:
const elfio& elf_file; const elfio& elf_file;
S* relocation_section; S* relocation_section = nullptr;
}; };
using relocation_section_accessor = using relocation_section_accessor =

View File

@ -33,7 +33,7 @@ template <class S> class versym_section_accessor_template
explicit versym_section_accessor_template( S* section ) explicit versym_section_accessor_template( S* section )
: versym_section( section ) : versym_section( section )
{ {
if ( section ) { if ( section != nullptr ) {
entries_num = decltype( entries_num )( section->get_size() / entries_num = decltype( entries_num )( section->get_size() /
sizeof( Elf_Half ) ); sizeof( Elf_Half ) );
} }
@ -85,8 +85,8 @@ template <class S> class versym_section_accessor_template
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
private: private:
S* versym_section; S* versym_section = nullptr;
Elf_Word entries_num; Elf_Word entries_num = 0;
}; };
using versym_section_accessor = versym_section_accessor_template<section>; using versym_section_accessor = versym_section_accessor_template<section>;
@ -166,8 +166,8 @@ template <class S> class versym_r_section_accessor_template
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
private: private:
const elfio& elf_file; const elfio& elf_file;
S* versym_r_section; S* versym_r_section = nullptr;
Elf_Word entries_num; Elf_Word entries_num = 0;
}; };
using versym_r_section_accessor = versym_r_section_accessor_template<section>; using versym_r_section_accessor = versym_r_section_accessor_template<section>;

View File

@ -62,7 +62,7 @@ void checkHeader( elfio& reader,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void checkSection( const section* sec, void checkSection( const section* sec,
Elf_Half index, Elf_Half index,
std::string name, const std::string& name,
Elf_Word type, Elf_Word type,
Elf_Xword flags, Elf_Xword flags,
Elf64_Addr address, Elf64_Addr address,
@ -122,7 +122,7 @@ void checkSegment( const segment* seg,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void checkSymbol( const symbol_section_accessor& sr, void checkSymbol( const symbol_section_accessor& sr,
Elf_Xword index, Elf_Xword index,
std::string name_, const std::string& name_,
Elf64_Addr value_, Elf64_Addr value_,
Elf_Xword size_, Elf_Xword size_,
unsigned char bind_, unsigned char bind_,
@ -155,7 +155,7 @@ void checkRelocation( const relocation_section_accessor* pRT,
Elf_Xword index, Elf_Xword index,
Elf64_Addr offset_, Elf64_Addr offset_,
Elf64_Addr symbolValue_, Elf64_Addr symbolValue_,
std::string symbolName_, const std::string& symbolName_,
unsigned char type_, unsigned char type_,
Elf_Sxword addend_, Elf_Sxword addend_,
Elf_Sxword calcValue_ ) Elf_Sxword calcValue_ )
@ -182,7 +182,7 @@ void checkRelocation( const relocation_section_accessor* pRT,
void checkNote( const note_section_accessor& notes, void checkNote( const note_section_accessor& notes,
Elf_Word index, Elf_Word index,
Elf_Word type_, Elf_Word type_,
std::string name_, const std::string& name_,
Elf_Word descSize_ ) Elf_Word descSize_ )
{ {
Elf_Word type; Elf_Word type;
@ -913,7 +913,7 @@ TEST( ELFIOTest, test_dynamic_64_1 )
ASSERT_EQ( reader.load( "elf_examples/main" ), true ); ASSERT_EQ( reader.load( "elf_examples/main" ), true );
section* dynsec = reader.sections[".dynamic"]; section* dynsec = reader.sections[".dynamic"];
ASSERT_TRUE( dynsec != NULL ); ASSERT_TRUE( dynsec != nullptr );
dynamic_section_accessor da( reader, dynsec ); dynamic_section_accessor da( reader, dynsec );
@ -947,7 +947,7 @@ TEST( ELFIOTest, test_dynamic_64_2 )
ASSERT_EQ( reader.load( "elf_examples/libfunc.so" ), true ); ASSERT_EQ( reader.load( "elf_examples/libfunc.so" ), true );
section* dynsec = reader.sections[".dynamic"]; section* dynsec = reader.sections[".dynamic"];
ASSERT_TRUE( dynsec != NULL ); ASSERT_TRUE( dynsec != nullptr );
dynamic_section_accessor da( reader, dynsec ); dynamic_section_accessor da( reader, dynsec );
@ -978,7 +978,7 @@ TEST( ELFIOTest, test_dynamic_64_3 )
ASSERT_EQ( reader.load( "elf_examples/main" ), true ); ASSERT_EQ( reader.load( "elf_examples/main" ), true );
section* dynsec = reader.sections[".dynamic"]; section* dynsec = reader.sections[".dynamic"];
ASSERT_TRUE( dynsec != NULL ); ASSERT_TRUE( dynsec != nullptr );
dynamic_section_accessor da( reader, dynsec ); dynamic_section_accessor da( reader, dynsec );
EXPECT_EQ( da.get_entries_num(), 21 ); EXPECT_EQ( da.get_entries_num(), 21 );
@ -993,9 +993,12 @@ TEST( ELFIOTest, test_dynamic_64_3 )
dynsec1->set_link( strsec1->get_index() ); dynsec1->set_link( strsec1->get_index() );
dynamic_section_accessor da1( reader, dynsec1 ); dynamic_section_accessor da1( reader, dynsec1 );
Elf_Xword tag, tag1; Elf_Xword tag;
Elf_Xword value, value1; Elf_Xword tag1;
std::string str, str1; Elf_Xword value;
Elf_Xword value1;
std::string str;
std::string str1;
for ( unsigned int i = 0; i < da.get_entries_num(); ++i ) { for ( unsigned int i = 0; i < da.get_entries_num(); ++i ) {
da.get_entry( i, tag, value, str ); da.get_entry( i, tag, value, str );