modernize-use-nullptr

This commit is contained in:
Serge Lamikhov-Center 2021-08-26 12:52:23 +03:00
parent 1f79600cec
commit 4a84319bb8
7 changed files with 31 additions and 30 deletions

View File

@ -70,7 +70,7 @@ class elfio
//------------------------------------------------------------------------------
elfio() : sections( this ), segments( this )
{
header = 0;
header = nullptr;
current_file_pos = 0;
create( ELFCLASS32, ELFDATA2LSB );
}
@ -135,7 +135,7 @@ class elfio
convertor.setup( e_ident[EI_DATA] );
header = create_header( e_ident[EI_CLASS], e_ident[EI_DATA] );
if ( 0 == header ) {
if ( nullptr == header ) {
return false;
}
if ( !header->load( stream ) ) {
@ -336,14 +336,14 @@ class elfio
is_offset_in_section( offset, sec ) )
return sec;
}
return NULL;
return nullptr;
}
//------------------------------------------------------------------------------
void clean()
{
delete header;
header = 0;
header = nullptr;
for ( auto it : sections_ ) {
delete it;
@ -360,7 +360,7 @@ class elfio
elf_header* create_header( unsigned char file_class,
unsigned char encoding )
{
elf_header* new_header = 0;
elf_header* new_header = nullptr;
if ( file_class == ELFCLASS64 ) {
new_header =
@ -371,7 +371,7 @@ class elfio
new elf_header_impl<Elf32_Ehdr>( &convertor, encoding );
}
else {
return 0;
return nullptr;
}
return new_header;
@ -390,7 +390,7 @@ class elfio
new_section = new section_impl<Elf32_Shdr>( &convertor );
}
else {
return 0;
return nullptr;
}
new_section->set_index( (Elf_Half)sections_.size() );
@ -412,7 +412,7 @@ class elfio
new_segment = new segment_impl<Elf32_Phdr>( &convertor );
}
else {
return 0;
return nullptr;
}
new_segment->set_index( (Elf_Half)segments_.size() );
@ -461,7 +461,7 @@ class elfio
for ( Elf_Half i = 0; i < num; ++i ) {
Elf_Word section_offset = sections[i]->get_name_string_offset();
const char* p = str_reader.get_string( section_offset );
if ( p != 0 ) {
if ( p != nullptr ) {
sections[i]->set_name( p );
}
}
@ -853,7 +853,7 @@ class elfio
//------------------------------------------------------------------------------
section* operator[]( unsigned int index ) const
{
section* sec = 0;
section* sec = nullptr;
if ( index < parent->sections_.size() ) {
sec = parent->sections_[index];
@ -865,7 +865,7 @@ class elfio
//------------------------------------------------------------------------------
section* operator[]( const std::string& name ) const
{
section* sec = 0;
section* sec = nullptr;
for ( auto it : parent->sections_ ) {
if ( it->get_name() == name ) {

View File

@ -82,7 +82,7 @@ template <class S> class dynamic_section_accessor_template
string_section_accessor strsec =
elf_file.sections[get_string_table_index()];
const char* result = strsec.get_string( value );
if ( 0 == result ) {
if ( nullptr == result ) {
str.clear();
return false;
}

View File

@ -82,7 +82,7 @@ template <class S> class note_section_accessor_template
}
name.assign( pData + 3 * (size_t)align, namesz - 1 );
if ( 0 == descSize ) {
desc = 0;
desc = nullptr;
}
else {
desc = const_cast<char*>( pData + 3 * (size_t)align +
@ -116,7 +116,7 @@ template <class S> class note_section_accessor_template
if ( nameLen % align != 0 ) {
buffer.append( pad, (size_t)align - nameLen % align );
}
if ( desc != 0 && descSize != 0 ) {
if ( desc != nullptr && descSize != 0 ) {
buffer.append( reinterpret_cast<const char*>( desc ), descSize );
if ( descSize % align != 0 ) {
buffer.append( pad, (size_t)align - descSize % align );
@ -139,7 +139,7 @@ template <class S> class note_section_accessor_template
note_start_positions.clear();
// Is it empty?
if ( 0 == data || 0 == size ) {
if ( nullptr == data || 0 == size ) {
return;
}

View File

@ -78,7 +78,7 @@ template <class T> class section_impl : public section
std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ),
'\0' );
is_address_set = false;
data = 0;
data = nullptr;
data_size = 0;
index = 0;
stream_size = 0;
@ -128,7 +128,7 @@ template <class T> class section_impl : public section
if ( get_type() != SHT_NOBITS ) {
delete[] data;
data = new ( std::nothrow ) char[size];
if ( 0 != data && 0 != raw_data ) {
if ( nullptr != data && nullptr != raw_data ) {
data_size = size;
std::copy( raw_data, raw_data + size, data );
}
@ -157,7 +157,7 @@ template <class T> class section_impl : public section
data_size = 2 * ( data_size + size );
char* new_data = new ( std::nothrow ) char[data_size];
if ( 0 != new_data ) {
if ( nullptr != new_data ) {
std::copy( data, data + get_size(), new_data );
std::copy( raw_data, raw_data + size,
new_data + get_size() );
@ -199,11 +199,11 @@ template <class T> class section_impl : public section
stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) );
Elf_Xword size = get_size();
if ( 0 == data && SHT_NULL != get_type() && SHT_NOBITS != get_type() &&
size < get_stream_size() ) {
if ( nullptr == data && SHT_NULL != get_type() &&
SHT_NOBITS != get_type() && size < get_stream_size() ) {
data = new ( std::nothrow ) char[size + 1];
if ( ( 0 != size ) && ( 0 != data ) ) {
if ( ( 0 != size ) && ( nullptr != data ) ) {
stream.seekg( ( *convertor )( header.sh_offset ) );
stream.read( data, size );
data[size] = 0; // Ensure data is ended with 0 to avoid oob read
@ -227,7 +227,7 @@ template <class T> class section_impl : public section
save_header( stream, header_offset );
if ( get_type() != SHT_NOBITS && get_type() != SHT_NULL &&
get_size() != 0 && data != 0 ) {
get_size() != 0 && data != nullptr ) {
save_data( stream, data_offset );
}
}

View File

@ -72,7 +72,7 @@ template <class T> class segment_impl : public segment
public:
//------------------------------------------------------------------------------
segment_impl( endianess_convertor* convertor )
: stream_size( 0 ), index( 0 ), data( 0 ), convertor( convertor )
: stream_size( 0 ), index( 0 ), data( nullptr ), convertor( convertor )
{
is_offset_set = false;
std::fill_n( reinterpret_cast<char*>( &ph ), sizeof( ph ), '\0' );
@ -172,12 +172,12 @@ template <class T> class segment_impl : public segment
Elf_Xword size = get_file_size();
if ( size > get_stream_size() ) {
data = 0;
data = nullptr;
}
else {
data = new ( std::nothrow ) char[size + 1];
if ( 0 != data ) {
if ( nullptr != data ) {
stream.read( data, size );
data[size] = 0;
}

View File

@ -44,13 +44,13 @@ template <class S> class string_section_accessor_template
if ( string_section ) {
if ( index < string_section->get_size() ) {
const char* data = string_section->get_data();
if ( 0 != data ) {
if ( nullptr != data ) {
return data + index;
}
}
}
return 0;
return nullptr;
}
//------------------------------------------------------------------------------

View File

@ -33,7 +33,7 @@ template <class S> class symbol_section_accessor_template
symbol_section_accessor_template( const elfio& elf_file, S* symbol_section )
: elf_file( elf_file ), symbol_section( symbol_section )
{
hash_section = 0;
hash_section = nullptr;
hash_section_index = 0;
find_hash_section();
}
@ -423,7 +423,8 @@ template <class S> class symbol_section_accessor_template
{
bool ret = false;
if ( 0 != symbol_section->get_data() && index < get_symbols_num() ) {
if ( nullptr != symbol_section->get_data() &&
index < get_symbols_num() ) {
const T* pSym = reinterpret_cast<const T*>(
symbol_section->get_data() +
index * symbol_section->get_entry_size() );
@ -435,7 +436,7 @@ template <class S> class symbol_section_accessor_template
string_section_accessor str_reader( string_section );
const char* pStr =
str_reader.get_string( convertor( pSym->st_name ) );
if ( 0 != pStr ) {
if ( nullptr != pStr ) {
name = pStr;
}
value = convertor( pSym->st_value );