From a8831c5d747f099d46144a41cef16bcc4296aab6 Mon Sep 17 00:00:00 2001 From: Serge Lamikhov-Center Date: Fri, 30 Oct 2020 18:06:26 +0200 Subject: [PATCH] Address warnings reported by MS VS analyzer --- elfio/elfio_note.hpp | 16 ++++++++-------- examples/c_wrapper/elfio_c_wrapper.cpp | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/elfio/elfio_note.hpp b/elfio/elfio_note.hpp index e7c4d3c..c1fd981 100644 --- a/elfio/elfio_note.hpp +++ b/elfio/elfio_note.hpp @@ -70,7 +70,7 @@ template class note_section_accessor_template int align = sizeof( Elf_Word ); const endianess_convertor& convertor = elf_file.get_convertor(); - type = convertor( *(const Elf_Word*)( pData + 2 * align ) ); + type = convertor( *(const Elf_Word*)( pData + 2 * (size_t)align ) ); Elf_Word namesz = convertor( *(const Elf_Word*)( pData ) ); descSize = convertor( *(const Elf_Word*)( pData + sizeof( namesz ) ) ); @@ -80,14 +80,14 @@ template class note_section_accessor_template (Elf_Xword)namesz + descSize > max_name_size ) { return false; } - name.assign( pData + 3 * align, namesz - 1 ); + name.assign( pData + 3 * (size_t)align, namesz - 1 ); if ( 0 == descSize ) { desc = 0; } else { - desc = - const_cast( pData + 3 * align + - ( ( namesz + align - 1 ) / align ) * align ); + desc = const_cast( pData + 3 * (size_t)align + + ( ( namesz + align - 1 ) / align ) * + (size_t)align ); } return true; @@ -106,7 +106,7 @@ template class note_section_accessor_template Elf_Word nameLenConv = convertor( nameLen ); std::string buffer( reinterpret_cast( &nameLenConv ), align ); Elf_Word descSizeConv = convertor( descSize ); - + buffer.append( reinterpret_cast( &descSizeConv ), align ); type = convertor( type ); buffer.append( reinterpret_cast( &type ), align ); @@ -114,12 +114,12 @@ template class note_section_accessor_template buffer.append( 1, '\x00' ); const char pad[] = { '\0', '\0', '\0', '\0' }; if ( nameLen % align != 0 ) { - buffer.append( pad, align - nameLen % align ); + buffer.append( pad, (size_t)align - nameLen % align ); } if ( desc != 0 && descSize != 0 ) { buffer.append( reinterpret_cast( desc ), descSize ); if ( descSize % align != 0 ) { - buffer.append( pad, (size_t)( align - descSize % align ) ); + buffer.append( pad, (size_t)align - descSize % align ); } } diff --git a/examples/c_wrapper/elfio_c_wrapper.cpp b/examples/c_wrapper/elfio_c_wrapper.cpp index 7122a61..8961ca2 100644 --- a/examples/c_wrapper/elfio_c_wrapper.cpp +++ b/examples/c_wrapper/elfio_c_wrapper.cpp @@ -125,7 +125,7 @@ ELFIO_C_GET_ACCESS_IMPL( section, Elf64_Off, offset ); void elfio_section_get_name( psection_t psection, char* buffer, int len ) { - strncpy( buffer, psection->get_name().c_str(), len - 1 ); + strncpy( buffer, psection->get_name().c_str(), (size_t)len - 1 ); } void elfio_section_set_name( psection_t psection, char* buffer ) @@ -225,7 +225,7 @@ bool elfio_symbol_get_symbol( psymbol_t psymbol, std::string name_param; bool ret = psymbol->get_symbol( index, name_param, *value, *size, *bind, *type, *section_index, *other ); - strncpy( name, name_param.c_str(), name_len - 1 ); + strncpy( name, name_param.c_str(), (size_t)name_len - 1 ); return ret; } @@ -350,7 +350,7 @@ bool elfio_note_get_note( pnote_t pnote, { std::string name_str; bool ret = pnote->get_note( index, *type, name_str, *desc, *descSize ); - strncpy( name, name_str.c_str(), name_len - 1 ); + strncpy( name, name_str.c_str(), (size_t)name_len - 1 ); return ret; } @@ -392,8 +392,8 @@ bool elfio_modinfo_get_attribute( pmodinfo_t pmodinfo, std::string field_str; std::string value_str; bool ret = pmodinfo->get_attribute( no, field_str, value_str ); - strncpy( field, field_str.c_str(), field_len - 1 ); - strncpy( value, value_str.c_str(), value_len - 1 ); + strncpy( field, field_str.c_str(), (size_t)field_len - 1 ); + strncpy( value, value_str.c_str(), (size_t)value_len - 1 ); return ret; } @@ -405,7 +405,7 @@ bool elfio_modinfo_get_attribute_by_name( pmodinfo_t pmodinfo, { std::string value_str; bool ret = pmodinfo->get_attribute( value_str, value_str ); - strncpy( value, value_str.c_str(), value_len - 1 ); + strncpy( value, value_str.c_str(), (size_t)value_len - 1 ); return ret; } @@ -444,7 +444,7 @@ bool elfio_dynamic_get_entry( pdynamic_t pdynamic, { std::string str_str; bool ret = pdynamic->get_entry( index, *tag, *value, str_str ); - strncpy( str, str_str.c_str(), str_len - 1 ); + strncpy( str, str_str.c_str(), (size_t)str_len - 1 ); return ret; }