'noexept' added to upper level API members

This commit is contained in:
Serge Lamikhov-Center 2022-11-12 17:00:08 +02:00
parent ad8b641f96
commit 4320ea915e
6 changed files with 142 additions and 106 deletions

View File

@ -42,17 +42,17 @@ THE SOFTWARE.
#include <elfio/elfio_strings.hpp>
#define ELFIO_HEADER_ACCESS_GET( TYPE, FNAME ) \
TYPE get_##FNAME() const \
TYPE get_##FNAME() const noexcept \
{ \
return header ? ( header->get_##FNAME() ) : 0; \
}
#define ELFIO_HEADER_ACCESS_GET_SET( TYPE, FNAME ) \
TYPE get_##FNAME() const \
TYPE get_##FNAME() const noexcept \
{ \
return header ? ( header->get_##FNAME() ) : 0; \
} \
void set_##FNAME( TYPE val ) \
void set_##FNAME( TYPE val ) noexcept \
{ \
if ( header ) { \
header->set_##FNAME( val ); \
@ -123,7 +123,7 @@ class elfio
// clang-format on
//------------------------------------------------------------------------------
void create( unsigned char file_class, unsigned char encoding )
void create( unsigned char file_class, unsigned char encoding ) noexcept
{
sections_.clear();
segments_.clear();
@ -132,13 +132,14 @@ class elfio
create_mandatory_sections();
}
void set_address_translation( std::vector<address_translation>& addr_trans )
void set_address_translation(
std::vector<address_translation>& addr_trans ) noexcept
{
addr_translator.set_address_translation( addr_trans );
}
//------------------------------------------------------------------------------
bool load( const std::string& file_name, bool is_lazy = false )
bool load( const std::string& file_name, bool is_lazy = false ) noexcept
{
std::ifstream stream;
stream.open( file_name.c_str(), std::ios::in | std::ios::binary );
@ -150,7 +151,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool load( std::istream& stream, bool is_lazy = false )
bool load( std::istream& stream, bool is_lazy = false ) noexcept
{
sections_.clear();
segments_.clear();
@ -192,7 +193,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool save( const std::string& file_name )
bool save( const std::string& file_name ) noexcept
{
std::ofstream stream;
stream.open( file_name.c_str(), std::ios::out | std::ios::binary );
@ -204,7 +205,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool save( std::ostream& stream )
bool save( std::ostream& stream ) noexcept
{
if ( !stream || header == nullptr ) {
return false;
@ -260,10 +261,13 @@ class elfio
ELFIO_HEADER_ACCESS_GET_SET( Elf_Half, section_name_str_index );
//------------------------------------------------------------------------------
const endianess_convertor& get_convertor() const { return convertor; }
const endianess_convertor& get_convertor() const noexcept
{
return convertor;
}
//------------------------------------------------------------------------------
Elf_Xword get_default_entry_size( Elf_Word section_type ) const
Elf_Xword get_default_entry_size( Elf_Word section_type ) const noexcept
{
switch ( section_type ) {
case SHT_RELA:
@ -303,7 +307,7 @@ class elfio
//! returns an empty string if no problems are detected,
//! or a string containing an error message if problems are found,
//! with one error per line.
std::string validate() const
std::string validate() const noexcept
{
// clang-format off
@ -365,20 +369,23 @@ class elfio
private:
//------------------------------------------------------------------------------
static bool is_offset_in_section( Elf64_Off offset, const section* sec )
static bool is_offset_in_section( Elf64_Off offset,
const section* sec ) noexcept
{
return ( offset >= sec->get_offset() ) &&
( offset < ( sec->get_offset() + sec->get_size() ) );
}
//------------------------------------------------------------------------------
static Elf64_Addr get_virtual_addr( Elf64_Off offset, const section* sec )
static Elf64_Addr get_virtual_addr( Elf64_Off offset,
const section* sec ) noexcept
{
return sec->get_address() + offset - sec->get_offset();
}
//------------------------------------------------------------------------------
const section* find_prog_section_for_offset( Elf64_Off offset ) const
const section*
find_prog_section_for_offset( Elf64_Off offset ) const noexcept
{
for ( const auto& sec : sections ) {
if ( sec->get_type() == SHT_PROGBITS &&
@ -391,18 +398,18 @@ class elfio
//------------------------------------------------------------------------------
std::unique_ptr<elf_header> create_header( unsigned char file_class,
unsigned char encoding )
unsigned char encoding ) noexcept
{
std::unique_ptr<elf_header> new_header;
if ( file_class == ELFCLASS64 ) {
new_header =
std::unique_ptr<elf_header>( new elf_header_impl<Elf64_Ehdr>(
new_header = std::unique_ptr<elf_header>(
new ( std::nothrow ) elf_header_impl<Elf64_Ehdr>(
&convertor, encoding, &addr_translator ) );
}
else if ( file_class == ELFCLASS32 ) {
new_header =
std::unique_ptr<elf_header>( new elf_header_impl<Elf32_Ehdr>(
new_header = std::unique_ptr<elf_header>(
new ( std::nothrow ) elf_header_impl<Elf32_Ehdr>(
&convertor, encoding, &addr_translator ) );
}
else {
@ -413,17 +420,19 @@ class elfio
}
//------------------------------------------------------------------------------
section* create_section()
section* create_section() noexcept
{
unsigned char file_class = get_class();
if ( file_class == ELFCLASS64 ) {
sections_.emplace_back( new section_impl<Elf64_Shdr>(
&convertor, &addr_translator, compression ) );
sections_.emplace_back(
new ( std::nothrow ) section_impl<Elf64_Shdr>(
&convertor, &addr_translator, compression ) );
}
else if ( file_class == ELFCLASS32 ) {
sections_.emplace_back( new section_impl<Elf32_Shdr>(
&convertor, &addr_translator, compression ) );
sections_.emplace_back(
new ( std::nothrow ) section_impl<Elf32_Shdr>(
&convertor, &addr_translator, compression ) );
}
else {
sections_.pop_back();
@ -437,17 +446,19 @@ class elfio
}
//------------------------------------------------------------------------------
segment* create_segment()
segment* create_segment() noexcept
{
unsigned char file_class = header->get_class();
if ( file_class == ELFCLASS64 ) {
segments_.emplace_back(
new segment_impl<Elf64_Phdr>( &convertor, &addr_translator ) );
new ( std::nothrow )
segment_impl<Elf64_Phdr>( &convertor, &addr_translator ) );
}
else if ( file_class == ELFCLASS32 ) {
segments_.emplace_back(
new segment_impl<Elf32_Phdr>( &convertor, &addr_translator ) );
new ( std::nothrow )
segment_impl<Elf32_Phdr>( &convertor, &addr_translator ) );
}
else {
segments_.pop_back();
@ -461,7 +472,7 @@ class elfio
}
//------------------------------------------------------------------------------
void create_mandatory_sections()
void create_mandatory_sections() noexcept
{
// Create null section without calling to 'add_section' as no string
// section containing section names exists yet
@ -477,7 +488,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool load_sections( std::istream& stream )
bool load_sections( std::istream& stream ) noexcept
{
unsigned char file_class = header->get_class();
Elf_Half entry_size = header->get_section_entry_size();
@ -524,7 +535,7 @@ class elfio
static bool is_sect_in_seg( Elf64_Off sect_begin,
Elf_Xword sect_size,
Elf64_Off seg_begin,
Elf64_Off seg_end )
Elf64_Off seg_end ) noexcept
{
return ( seg_begin <= sect_begin ) &&
( sect_begin + sect_size <= seg_end ) &&
@ -535,7 +546,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool load_segments( std::istream& stream, bool is_lazy )
bool load_segments( std::istream& stream, bool is_lazy ) noexcept
{
unsigned char file_class = header->get_class();
Elf_Half entry_size = header->get_segment_entry_size();
@ -551,12 +562,14 @@ class elfio
for ( Elf_Half i = 0; i < num; ++i ) {
if ( file_class == ELFCLASS64 ) {
segments_.emplace_back( new segment_impl<Elf64_Phdr>(
&convertor, &addr_translator ) );
segments_.emplace_back(
new ( std::nothrow ) segment_impl<Elf64_Phdr>(
&convertor, &addr_translator ) );
}
else if ( file_class == ELFCLASS32 ) {
segments_.emplace_back( new segment_impl<Elf32_Phdr>(
&convertor, &addr_translator ) );
segments_.emplace_back(
new ( std::nothrow ) segment_impl<Elf32_Phdr>(
&convertor, &addr_translator ) );
}
else {
segments_.pop_back();
@ -565,9 +578,10 @@ class elfio
segment* seg = segments_.back().get();
if ( !seg->load( stream, static_cast<std::streamoff>( offset ) +
static_cast<std::streampos>( i ) *
entry_size, is_lazy ) ||
if ( !seg->load( stream,
static_cast<std::streamoff>( offset ) +
static_cast<std::streampos>( i ) * entry_size,
is_lazy ) ||
stream.fail() ) {
segments_.pop_back();
return false;
@ -600,10 +614,13 @@ class elfio
}
//------------------------------------------------------------------------------
bool save_header( std::ostream& stream ) { return header->save( stream ); }
bool save_header( std::ostream& stream ) const noexcept
{
return header->save( stream );
}
//------------------------------------------------------------------------------
bool save_sections( std::ostream& stream )
bool save_sections( std::ostream& stream ) const noexcept
{
for ( const auto& sec : sections_ ) {
std::streampos headerPosition =
@ -618,7 +635,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool save_segments( std::ostream& stream )
bool save_segments( std::ostream& stream ) const noexcept
{
for ( const auto& seg : segments_ ) {
std::streampos headerPosition =
@ -633,7 +650,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool is_section_without_segment( unsigned int section_index ) const
bool is_section_without_segment( unsigned int section_index ) const noexcept
{
bool found = false;
@ -648,7 +665,8 @@ class elfio
}
//------------------------------------------------------------------------------
static bool is_subsequence_of( const segment* seg1, const segment* seg2 )
static bool is_subsequence_of( const segment* seg1,
const segment* seg2 ) noexcept
{
// Return 'true' if sections of seg1 are a subset of sections in seg2
const std::vector<Elf_Half>& sections1 = seg1->get_sections();
@ -664,7 +682,7 @@ class elfio
}
//------------------------------------------------------------------------------
std::vector<segment*> get_ordered_segments()
std::vector<segment*> get_ordered_segments() const noexcept
{
std::vector<segment*> res;
std::deque<segment*> worklist;
@ -710,7 +728,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool layout_sections_without_segments()
bool layout_sections_without_segments() noexcept
{
for ( unsigned int i = 0; i < sections_.size(); ++i ) {
if ( is_section_without_segment( i ) ) {
@ -738,7 +756,7 @@ class elfio
}
//------------------------------------------------------------------------------
void calc_segment_alignment()
void calc_segment_alignment() const noexcept
{
for ( const auto& seg : segments_ ) {
for ( Elf_Half i = 0; i < seg->get_sections_num(); ++i ) {
@ -751,7 +769,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool layout_segments_and_their_sections()
bool layout_segments_and_their_sections() noexcept
{
std::vector<segment*> worklist;
std::vector<bool> section_generated( sections.size(), false );
@ -820,7 +838,7 @@ class elfio
}
//------------------------------------------------------------------------------
bool layout_section_table()
bool layout_section_table() noexcept
{
// Simply place the section table at the end for now
Elf64_Off alignmentError = current_file_pos % 4;
@ -834,7 +852,7 @@ class elfio
std::vector<bool>& section_generated,
Elf_Xword& segment_memory,
Elf_Xword& segment_filesize,
const Elf_Xword& seg_start_pos )
const Elf_Xword& seg_start_pos ) noexcept
{
for ( Elf_Half j = 0; j < seg->get_sections_num(); ++j ) {
Elf_Half index = seg->get_section_index_at( j );
@ -931,13 +949,13 @@ class elfio
explicit Sections( elfio* parent ) : parent( parent ) {}
//------------------------------------------------------------------------------
Elf_Half size() const
Elf_Half size() const noexcept
{
return static_cast<Elf_Half>( parent->sections_.size() );
}
//------------------------------------------------------------------------------
section* operator[]( unsigned int index ) const
section* operator[]( unsigned int index ) const noexcept
{
section* sec = nullptr;
@ -949,7 +967,7 @@ class elfio
}
//------------------------------------------------------------------------------
section* operator[]( const std::string& name ) const
section* operator[]( const std::string& name ) const noexcept
{
section* sec = nullptr;
@ -964,7 +982,7 @@ class elfio
}
//------------------------------------------------------------------------------
section* add( const std::string& name )
section* add( const std::string& name ) const noexcept
{
section* new_section = parent->create_section();
new_section->set_name( name );
@ -979,25 +997,27 @@ class elfio
}
//------------------------------------------------------------------------------
std::vector<std::unique_ptr<section>>::iterator begin()
std::vector<std::unique_ptr<section>>::iterator begin() noexcept
{
return parent->sections_.begin();
}
//------------------------------------------------------------------------------
std::vector<std::unique_ptr<section>>::iterator end()
std::vector<std::unique_ptr<section>>::iterator end() noexcept
{
return parent->sections_.end();
}
//------------------------------------------------------------------------------
std::vector<std::unique_ptr<section>>::const_iterator begin() const
std::vector<std::unique_ptr<section>>::const_iterator
begin() const noexcept
{
return parent->sections_.cbegin();
}
//------------------------------------------------------------------------------
std::vector<std::unique_ptr<section>>::const_iterator end() const
std::vector<std::unique_ptr<section>>::const_iterator
end() const noexcept
{
return parent->sections_.cend();
}
@ -1017,40 +1037,42 @@ class elfio
explicit Segments( elfio* parent ) : parent( parent ) {}
//------------------------------------------------------------------------------
Elf_Half size() const
Elf_Half size() const noexcept
{
return static_cast<Elf_Half>( parent->segments_.size() );
}
//------------------------------------------------------------------------------
segment* operator[]( unsigned int index ) const
segment* operator[]( unsigned int index ) const noexcept
{
return parent->segments_[index].get();
}
//------------------------------------------------------------------------------
segment* add() { return parent->create_segment(); }
segment* add() noexcept { return parent->create_segment(); }
//------------------------------------------------------------------------------
std::vector<std::unique_ptr<segment>>::iterator begin()
std::vector<std::unique_ptr<segment>>::iterator begin() noexcept
{
return parent->segments_.begin();
}
//------------------------------------------------------------------------------
std::vector<std::unique_ptr<segment>>::iterator end()
std::vector<std::unique_ptr<segment>>::iterator end() noexcept
{
return parent->segments_.end();
}
//------------------------------------------------------------------------------
std::vector<std::unique_ptr<segment>>::const_iterator begin() const
std::vector<std::unique_ptr<segment>>::const_iterator
begin() const noexcept
{
return parent->segments_.cbegin();
}
//------------------------------------------------------------------------------
std::vector<std::unique_ptr<segment>>::const_iterator end() const
std::vector<std::unique_ptr<segment>>::const_iterator
end() const noexcept
{
return parent->segments_.cend();
}
@ -1063,7 +1085,8 @@ class elfio
//------------------------------------------------------------------------------
private:
std::unique_ptr<elf_header> header = nullptr;
std::ifstream* pstream = nullptr;
std::unique_ptr<elf_header> header = nullptr;
std::vector<std::unique_ptr<section>> sections_;
std::vector<std::unique_ptr<segment>> segments_;
endianess_convertor convertor;

View File

@ -94,19 +94,19 @@ template <class T> class section_impl : public section
ELFIO_GET_ACCESS( Elf64_Addr, address, header.sh_addr );
//------------------------------------------------------------------------------
Elf_Half get_index() const override { return index; }
Elf_Half get_index() const noexcept override { return index; }
//------------------------------------------------------------------------------
std::string get_name() const override { return name; }
std::string get_name() const noexcept override { return name; }
//------------------------------------------------------------------------------
void set_name( const std::string& name_prm ) override
void set_name( const std::string& name_prm ) noexcept override
{
this->name = name_prm;
}
//------------------------------------------------------------------------------
void set_address( const Elf64_Addr& value ) override
void set_address( const Elf64_Addr& value ) noexcept override
{
header.sh_addr = decltype( header.sh_addr )( value );
header.sh_addr = ( *convertor )( header.sh_addr );
@ -193,7 +193,7 @@ template <class T> class section_impl : public section
ELFIO_GET_SET_ACCESS( Elf64_Off, offset, header.sh_offset );
//------------------------------------------------------------------------------
void set_index( const Elf_Half& value ) override { index = value; }
void set_index( const Elf_Half& value ) noexcept override { index = value; }
//------------------------------------------------------------------------------
bool load( std::istream& stream, std::streampos header_offset ) override

View File

@ -64,7 +64,7 @@ class segment
virtual bool load( std::istream& stream,
std::streampos header_offset,
bool is_lazy = false ) = 0;
bool is_lazy ) = 0;
virtual void save( std::ostream& stream,
std::streampos header_offset,
std::streampos data_offset ) = 0;
@ -93,7 +93,7 @@ template <class T> class segment_impl : public segment
ELFIO_GET_ACCESS( Elf64_Off, offset, ph.p_offset );
//------------------------------------------------------------------------------
Elf_Half get_index() const override { return index; }
Elf_Half get_index() const noexcept override { return index; }
//------------------------------------------------------------------------------
const char* get_data() const override
@ -144,7 +144,7 @@ template <class T> class segment_impl : public segment
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void set_offset( const Elf64_Off& value ) override
void set_offset( const Elf64_Off& value ) noexcept override
{
ph.p_offset = decltype( ph.p_offset )( value );
ph.p_offset = ( *convertor )( ph.p_offset );
@ -161,12 +161,12 @@ template <class T> class segment_impl : public segment
}
//------------------------------------------------------------------------------
void set_index( const Elf_Half& value ) override { index = value; }
void set_index( const Elf_Half& value ) noexcept override { index = value; }
//------------------------------------------------------------------------------
bool load( std::istream& stream,
std::streampos header_offset,
bool is_lazy_ = false ) override
bool is_lazy_ ) override
{
pstream = &stream;
is_lazy = is_lazy_;
@ -190,6 +190,7 @@ template <class T> class segment_impl : public segment
return true;
}
//------------------------------------------------------------------------------
bool load_data() const
{
if ( PT_NULL == get_type() || 0 == get_file_size() ) {
@ -199,7 +200,7 @@ template <class T> class segment_impl : public segment
pstream->seekg( ( *translator )[( *convertor )( ph.p_offset )] );
Elf_Xword size = get_file_size();
if ( size > get_stream_size() || is_lazy ) {
if ( size > get_stream_size() ) {
data = nullptr;
}
else {
@ -207,6 +208,7 @@ template <class T> class segment_impl : public segment
if ( nullptr != data.get() && pstream->read( data.get(), size ) ) {
data.get()[size] = 0;
is_lazy = false;
}
else {
data = nullptr;

View File

@ -26,30 +26,37 @@ THE SOFTWARE.
#include <cstdint>
#include <ostream>
#define ELFIO_GET_ACCESS_DECL( TYPE, NAME ) virtual TYPE get_##NAME() const = 0
#define ELFIO_GET_ACCESS_DECL( TYPE, NAME ) \
virtual TYPE get_##NAME() const noexcept = 0
#define ELFIO_SET_ACCESS_DECL( TYPE, NAME ) \
virtual void set_##NAME( const TYPE& value ) = 0
virtual void set_##NAME( const TYPE& value ) noexcept = 0
#define ELFIO_GET_SET_ACCESS_DECL( TYPE, NAME ) \
virtual TYPE get_##NAME() const = 0; \
virtual void set_##NAME( const TYPE& value ) = 0
#define ELFIO_GET_SET_ACCESS_DECL( TYPE, NAME ) \
virtual TYPE get_##NAME() const noexcept = 0; \
virtual void set_##NAME( const TYPE& value ) noexcept = 0
#define ELFIO_GET_ACCESS( TYPE, NAME, FIELD ) \
TYPE get_##NAME() const override { return ( *convertor )( FIELD ); }
#define ELFIO_SET_ACCESS( TYPE, NAME, FIELD ) \
void set_##NAME( const TYPE& value ) override \
{ \
FIELD = decltype( FIELD )( value ); \
FIELD = ( *convertor )( FIELD ); \
TYPE get_##NAME() const noexcept override \
{ \
return ( *convertor )( FIELD ); \
}
#define ELFIO_GET_SET_ACCESS( TYPE, NAME, FIELD ) \
TYPE get_##NAME() const override { return ( *convertor )( FIELD ); } \
void set_##NAME( const TYPE& value ) override \
{ \
FIELD = decltype( FIELD )( value ); \
FIELD = ( *convertor )( FIELD ); \
#define ELFIO_SET_ACCESS( TYPE, NAME, FIELD ) \
void set_##NAME( const TYPE& value ) noexcept override \
{ \
FIELD = decltype( FIELD )( value ); \
FIELD = ( *convertor )( FIELD ); \
}
#define ELFIO_GET_SET_ACCESS( TYPE, NAME, FIELD ) \
TYPE get_##NAME() const noexcept override \
{ \
return ( *convertor )( FIELD ); \
} \
void set_##NAME( const TYPE& value ) noexcept override \
{ \
FIELD = decltype( FIELD )( value ); \
FIELD = ( *convertor )( FIELD ); \
}
namespace ELFIO {

View File

@ -34,7 +34,7 @@ using namespace ELFIO;
//-----------------------------------------------------------------------------
// elfio
//-----------------------------------------------------------------------------
pelfio_t elfio_new() { return new elfio; }
pelfio_t elfio_new() { return new ( std::nothrow ) elfio; }
void elfio_delete( pelfio_t pelfio ) { delete (elfio*)pelfio; }
@ -209,7 +209,7 @@ bool elfio_segment_is_offset_initialized( psegment_t psegment )
psymbol_t elfio_symbol_section_accessor_new( pelfio_t pelfio,
psection_t psection )
{
return new symbol_section_accessor( *pelfio, psection );
return new ( std::nothrow ) symbol_section_accessor( *pelfio, psection );
}
void elfio_symbol_section_accessor_delete( psymbol_t psymbol )
@ -264,7 +264,8 @@ Elf_Xword elfio_symbol_arrange_local_symbols(
prelocation_t elfio_relocation_section_accessor_new( pelfio_t pelfio,
psection_t psection )
{
return new relocation_section_accessor( *pelfio, psection );
return new ( std::nothrow )
relocation_section_accessor( *pelfio, psection );
}
void elfio_relocation_section_accessor_delete( prelocation_t prelocation )
@ -318,7 +319,7 @@ void elfio_relocation_swap_symbols( prelocation_t prelocation,
//-----------------------------------------------------------------------------
pstring_t elfio_string_section_accessor_new( psection_t psection )
{
return new string_section_accessor( psection );
return new ( std::nothrow ) string_section_accessor( psection );
}
void elfio_string_section_accessor_delete( pstring_t pstring )
@ -341,7 +342,7 @@ Elf_Word elfio_string_add_string( pstring_t pstring, char* str )
//-----------------------------------------------------------------------------
pnote_t elfio_note_section_accessor_new( pelfio_t pelfio, psection_t psection )
{
return new note_section_accessor( *pelfio, psection );
return new ( std::nothrow ) note_section_accessor( *pelfio, psection );
}
void elfio_note_section_accessor_delete( pnote_t pnote ) { delete pnote; }
@ -380,7 +381,7 @@ void elfio_note_add_note( pnote_t pnote,
//-----------------------------------------------------------------------------
pmodinfo_t elfio_modinfo_section_accessor_new( psection_t psection )
{
return new modinfo_section_accessor( psection );
return new ( std::nothrow ) modinfo_section_accessor( psection );
}
void elfio_modinfo_section_accessor_delete( pmodinfo_t pmodinfo )
@ -433,7 +434,7 @@ elfio_modinfo_add_attribute( pmodinfo_t pmodinfo, char* field, char* value )
pdynamic_t elfio_dynamic_section_accessor_new( pelfio_t pelfio,
psection_t psection )
{
return new dynamic_section_accessor( *pelfio, psection );
return new ( std::nothrow ) dynamic_section_accessor( *pelfio, psection );
}
void elfio_dynamic_section_accessor_delete( pdynamic_t pdynamic )
@ -473,7 +474,8 @@ void elfio_dynamic_add_entry( pdynamic_t pdynamic,
parray_t elfio_array_section_accessor_new( pelfio_t pelfio,
psection_t psection )
{
return new array_section_accessor<Elf64_Word>( *pelfio, psection );
return new ( std::nothrow )
array_section_accessor<Elf64_Word>( *pelfio, psection );
}
void elfio_array_section_accessor_delete( parray_t parray ) { delete parray; }

View File

@ -981,7 +981,8 @@ class mock_wiiu_compression : public compression_interface
Elf_Xword& uncompressed_size ) const override
{
uncompressed_size = 2 * compressed_size;
return std::unique_ptr<char[]>( new char[uncompressed_size + 1] );
return std::unique_ptr<char[]>(
new ( std::nothrow ) char[uncompressed_size + 1] );
}
std::unique_ptr<char[]> deflate( const char* data,
@ -990,7 +991,8 @@ class mock_wiiu_compression : public compression_interface
Elf_Xword& compressed_size ) const override
{
compressed_size = decompressed_size / 2;
return std::unique_ptr<char[]>( new char[compressed_size + 1] );
return std::unique_ptr<char[]>(
new ( std::nothrow ) char[compressed_size + 1] );
}
};
@ -1005,7 +1007,7 @@ class mock_wiiu_compression : public compression_interface
// a real compression implementation
TEST( ELFIOTest, test_rpx )
{
elfio reader( new mock_wiiu_compression() );
elfio reader( new ( std::nothrow ) mock_wiiu_compression() );
elfio reader_no_compression;
ASSERT_EQ( reader_no_compression.load( "elf_examples/helloworld.rpx" ),