mirror of
https://github.com/serge1/ELFIO.git
synced 2025-03-28 16:20:53 +00:00
Address casting on MSVC++
This commit is contained in:
parent
590de384b8
commit
090444309f
@ -76,12 +76,12 @@ template <class S> class dynamic_section_accessor_template
|
|||||||
generic_get_entry_dyn<Elf64_Dyn>( index, tag, value );
|
generic_get_entry_dyn<Elf64_Dyn>( index, tag, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the tag may have a string table reference, prepare the string
|
// If the tag has a string table reference - prepare the string
|
||||||
if ( tag == DT_NEEDED || tag == DT_SONAME || tag == DT_RPATH ||
|
if ( tag == DT_NEEDED || tag == DT_SONAME || tag == DT_RPATH ||
|
||||||
tag == DT_RUNPATH ) {
|
tag == DT_RUNPATH ) {
|
||||||
string_section_accessor strsec(
|
string_section_accessor strsec(
|
||||||
elf_file.sections[get_string_table_index()] );
|
elf_file.sections[get_string_table_index()] );
|
||||||
const char* result = strsec.get_string( value );
|
const char* result = strsec.get_string( (Elf_Word)value );
|
||||||
if ( nullptr == result ) {
|
if ( nullptr == result ) {
|
||||||
str.clear();
|
str.clear();
|
||||||
return false;
|
return false;
|
||||||
|
@ -376,7 +376,7 @@ template <class S> class relocation_section_accessor_template
|
|||||||
else {
|
else {
|
||||||
pEntry->r_info = ELF64_R_INFO( (Elf_Xword)symbol, type );
|
pEntry->r_info = ELF64_R_INFO( (Elf_Xword)symbol, type );
|
||||||
}
|
}
|
||||||
pEntry->r_offset = offset;
|
pEntry->r_offset = decltype( pEntry->r_offset )( offset );
|
||||||
pEntry->r_offset = convertor( pEntry->r_offset );
|
pEntry->r_offset = convertor( pEntry->r_offset );
|
||||||
pEntry->r_info = convertor( pEntry->r_info );
|
pEntry->r_info = convertor( pEntry->r_info );
|
||||||
}
|
}
|
||||||
@ -401,8 +401,8 @@ template <class S> class relocation_section_accessor_template
|
|||||||
else {
|
else {
|
||||||
pEntry->r_info = ELF64_R_INFO( (Elf_Xword)symbol, type );
|
pEntry->r_info = ELF64_R_INFO( (Elf_Xword)symbol, type );
|
||||||
}
|
}
|
||||||
pEntry->r_offset = offset;
|
pEntry->r_offset = decltype( pEntry->r_offset )( offset );
|
||||||
pEntry->r_addend = addend;
|
pEntry->r_addend = decltype( pEntry->r_addend )( addend );
|
||||||
pEntry->r_offset = convertor( pEntry->r_offset );
|
pEntry->r_offset = convertor( pEntry->r_offset );
|
||||||
pEntry->r_info = convertor( pEntry->r_info );
|
pEntry->r_info = convertor( pEntry->r_info );
|
||||||
pEntry->r_addend = convertor( pEntry->r_addend );
|
pEntry->r_addend = convertor( pEntry->r_addend );
|
||||||
@ -415,8 +415,8 @@ template <class S> class relocation_section_accessor_template
|
|||||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||||
|
|
||||||
T entry;
|
T entry;
|
||||||
entry.r_offset = offset;
|
entry.r_offset = decltype( entry.r_offset )( offset );
|
||||||
entry.r_info = info;
|
entry.r_info = decltype( entry.r_info )( info );
|
||||||
entry.r_offset = convertor( entry.r_offset );
|
entry.r_offset = convertor( entry.r_offset );
|
||||||
entry.r_info = convertor( entry.r_info );
|
entry.r_info = convertor( entry.r_info );
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ template <class T> class section_impl : public section
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void set_address( Elf64_Addr value ) override
|
void set_address( Elf64_Addr value ) override
|
||||||
{
|
{
|
||||||
header.sh_addr = value;
|
header.sh_addr = decltype( header.sh_addr )( value );
|
||||||
header.sh_addr = ( *convertor )( header.sh_addr );
|
header.sh_addr = ( *convertor )( header.sh_addr );
|
||||||
is_address_set = true;
|
is_address_set = true;
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ template <class T> class section_impl : public section
|
|||||||
|
|
||||||
if ( translator->empty() ) {
|
if ( translator->empty() ) {
|
||||||
stream.seekg( 0, stream.end );
|
stream.seekg( 0, stream.end );
|
||||||
set_stream_size( stream.tellg() );
|
set_stream_size( size_t( stream.tellg() ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_stream_size( std::numeric_limits<size_t>::max() );
|
set_stream_size( std::numeric_limits<size_t>::max() );
|
||||||
@ -220,14 +220,14 @@ template <class T> class section_impl : public section
|
|||||||
Elf_Xword size = get_size();
|
Elf_Xword size = get_size();
|
||||||
if ( nullptr == data && SHT_NULL != get_type() &&
|
if ( nullptr == data && SHT_NULL != get_type() &&
|
||||||
SHT_NOBITS != get_type() && size < get_stream_size() ) {
|
SHT_NOBITS != get_type() && size < get_stream_size() ) {
|
||||||
data = new ( std::nothrow ) char[size + 1];
|
data = new ( std::nothrow ) char[size_t( size ) + 1];
|
||||||
|
|
||||||
if ( ( 0 != size ) && ( nullptr != data ) ) {
|
if ( ( 0 != size ) && ( nullptr != data ) ) {
|
||||||
stream.seekg(
|
stream.seekg(
|
||||||
( *translator )[( *convertor )( header.sh_offset )] );
|
( *translator )[( *convertor )( header.sh_offset )] );
|
||||||
stream.read( data, size );
|
stream.read( data, size );
|
||||||
data[size] = 0; // Ensure data is ended with 0 to avoid oob read
|
data[size] = 0; // Ensure data is ended with 0 to avoid oob read
|
||||||
data_size = size;
|
data_size = decltype( data_size )( size );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data_size = 0;
|
data_size = 0;
|
||||||
@ -241,7 +241,7 @@ template <class T> class section_impl : public section
|
|||||||
std::streampos data_offset ) override
|
std::streampos data_offset ) override
|
||||||
{
|
{
|
||||||
if ( 0 != get_index() ) {
|
if ( 0 != get_index() ) {
|
||||||
header.sh_offset = data_offset;
|
header.sh_offset = decltype( header.sh_offset )( data_offset );
|
||||||
header.sh_offset = ( *convertor )( header.sh_offset );
|
header.sh_offset = ( *convertor )( header.sh_offset );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ template <class T> class segment_impl : public segment
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void set_offset( Elf64_Off value ) override
|
void set_offset( Elf64_Off value ) override
|
||||||
{
|
{
|
||||||
ph.p_offset = value;
|
ph.p_offset = decltype( ph.p_offset )( value );
|
||||||
ph.p_offset = ( *convertor )( ph.p_offset );
|
ph.p_offset = ( *convertor )( ph.p_offset );
|
||||||
is_offset_set = true;
|
is_offset_set = true;
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ template <class T> class segment_impl : public segment
|
|||||||
{
|
{
|
||||||
if ( translator->empty() ) {
|
if ( translator->empty() ) {
|
||||||
stream.seekg( 0, stream.end );
|
stream.seekg( 0, stream.end );
|
||||||
set_stream_size( stream.tellg() );
|
set_stream_size( size_t( stream.tellg() ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_stream_size( std::numeric_limits<size_t>::max() );
|
set_stream_size( std::numeric_limits<size_t>::max() );
|
||||||
@ -181,7 +181,7 @@ template <class T> class segment_impl : public segment
|
|||||||
data = nullptr;
|
data = nullptr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data = new ( std::nothrow ) char[size + 1];
|
data = new ( std::nothrow ) char[(size_t)size + 1];
|
||||||
|
|
||||||
if ( nullptr != data ) {
|
if ( nullptr != data ) {
|
||||||
stream.read( data, size );
|
stream.read( data, size );
|
||||||
@ -196,7 +196,7 @@ template <class T> class segment_impl : public segment
|
|||||||
std::streampos header_offset,
|
std::streampos header_offset,
|
||||||
std::streampos data_offset ) override
|
std::streampos data_offset ) override
|
||||||
{
|
{
|
||||||
ph.p_offset = data_offset;
|
ph.p_offset = decltype( ph.p_offset )( data_offset );
|
||||||
ph.p_offset = ( *convertor )( ph.p_offset );
|
ph.p_offset = ( *convertor )( ph.p_offset );
|
||||||
adjust_stream_size( stream, header_offset );
|
adjust_stream_size( stream, header_offset );
|
||||||
stream.write( reinterpret_cast<const char*>( &ph ), sizeof( ph ) );
|
stream.write( reinterpret_cast<const char*>( &ph ), sizeof( ph ) );
|
||||||
|
@ -234,7 +234,7 @@ template <class S> class symbol_section_accessor_template
|
|||||||
std::function<void( Elf_Xword first, Elf_Xword second )> func =
|
std::function<void( Elf_Xword first, Elf_Xword second )> func =
|
||||||
nullptr )
|
nullptr )
|
||||||
{
|
{
|
||||||
int nRet = 0;
|
Elf_Xword nRet = 0;
|
||||||
|
|
||||||
if ( elf_file.get_class() == ELFCLASS32 ) {
|
if ( elf_file.get_class() == ELFCLASS32 ) {
|
||||||
nRet = generic_arrange_local_symbols<Elf32_Sym>( func );
|
nRet = generic_arrange_local_symbols<Elf32_Sym>( func );
|
||||||
@ -466,9 +466,9 @@ template <class S> class symbol_section_accessor_template
|
|||||||
|
|
||||||
T entry;
|
T entry;
|
||||||
entry.st_name = convertor( name );
|
entry.st_name = convertor( name );
|
||||||
entry.st_value = value;
|
entry.st_value = decltype( entry.st_value )( value );
|
||||||
entry.st_value = convertor( entry.st_value );
|
entry.st_value = convertor( entry.st_value );
|
||||||
entry.st_size = size;
|
entry.st_size = decltype( entry.st_size )( size );
|
||||||
entry.st_size = convertor( entry.st_size );
|
entry.st_size = convertor( entry.st_size );
|
||||||
entry.st_info = convertor( info );
|
entry.st_info = convertor( info );
|
||||||
entry.st_other = convertor( other );
|
entry.st_other = convertor( other );
|
||||||
@ -477,7 +477,8 @@ template <class S> class symbol_section_accessor_template
|
|||||||
symbol_section->append_data( reinterpret_cast<char*>( &entry ),
|
symbol_section->append_data( reinterpret_cast<char*>( &entry ),
|
||||||
sizeof( entry ) );
|
sizeof( entry ) );
|
||||||
|
|
||||||
Elf_Word nRet = symbol_section->get_size() / sizeof( entry ) - 1;
|
Elf_Word nRet =
|
||||||
|
Elf_Word( symbol_section->get_size() / sizeof( entry ) - 1 );
|
||||||
|
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
@ -489,7 +490,7 @@ template <class S> class symbol_section_accessor_template
|
|||||||
{
|
{
|
||||||
const endianess_convertor& convertor = elf_file.get_convertor();
|
const endianess_convertor& convertor = elf_file.get_convertor();
|
||||||
|
|
||||||
Elf_Xword first_not_local =
|
Elf_Word first_not_local =
|
||||||
1; // Skip the first entry. It is always NOTYPE
|
1; // Skip the first entry. It is always NOTYPE
|
||||||
Elf_Xword current = 0;
|
Elf_Xword current = 0;
|
||||||
Elf_Xword count = get_symbols_num();
|
Elf_Xword count = get_symbols_num();
|
||||||
|
@ -41,14 +41,14 @@ THE SOFTWARE.
|
|||||||
#define ELFIO_SET_ACCESS( TYPE, NAME, FIELD ) \
|
#define ELFIO_SET_ACCESS( TYPE, NAME, FIELD ) \
|
||||||
void set_##NAME( TYPE value ) override \
|
void set_##NAME( TYPE value ) override \
|
||||||
{ \
|
{ \
|
||||||
FIELD = value; \
|
FIELD = decltype( FIELD )( value ); \
|
||||||
FIELD = ( *convertor )( FIELD ); \
|
FIELD = ( *convertor )( FIELD ); \
|
||||||
}
|
}
|
||||||
#define ELFIO_GET_SET_ACCESS( TYPE, NAME, FIELD ) \
|
#define ELFIO_GET_SET_ACCESS( TYPE, NAME, FIELD ) \
|
||||||
TYPE get_##NAME() const override { return ( *convertor )( FIELD ); } \
|
TYPE get_##NAME() const override { return ( *convertor )( FIELD ); } \
|
||||||
void set_##NAME( TYPE value ) override \
|
void set_##NAME( TYPE value ) override \
|
||||||
{ \
|
{ \
|
||||||
FIELD = value; \
|
FIELD = decltype( FIELD )( value ); \
|
||||||
FIELD = ( *convertor )( FIELD ); \
|
FIELD = ( *convertor )( FIELD ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ inline void adjust_stream_size( std::ostream& stream, std::streamsize offset )
|
|||||||
stream.seekp( 0, std::ios_base::end );
|
stream.seekp( 0, std::ios_base::end );
|
||||||
if ( stream.tellp() < offset ) {
|
if ( stream.tellp() < offset ) {
|
||||||
std::streamsize size = offset - stream.tellp();
|
std::streamsize size = offset - stream.tellp();
|
||||||
stream.write( std::string( size, '\0' ).c_str(), size );
|
stream.write( std::string( size_t( size ), '\0' ).c_str(), size );
|
||||||
}
|
}
|
||||||
stream.seekp( offset );
|
stream.seekp( offset );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user