Rephrase condition of is_sect_in_seg() to make it more intuitive

This commit is contained in:
Martin Bickel 2017-03-04 22:57:38 +01:00 committed by Serge Lamikhov-Center
parent fe78d06e81
commit 3385408d6b

View File

@ -426,11 +426,11 @@ class elfio
//! It doesn't matter if the addresses are memory addresses, or file offsets, //! It doesn't matter if the addresses are memory addresses, or file offsets,
//! they just need to be in the same address space //! they just need to be in the same address space
bool is_sect_in_seg ( Elf64_Off sect_begin, Elf_Xword sect_size, Elf64_Off seg_begin, Elf64_Off seg_end ) { bool is_sect_in_seg ( Elf64_Off sect_begin, Elf_Xword sect_size, Elf64_Off seg_begin, Elf64_Off seg_end ) {
if ( sect_size > 0 ) { return seg_begin <= sect_begin
return seg_begin <= sect_begin && sect_begin + sect_size <= seg_end; && sect_begin + sect_size <= seg_end
} else { && sect_begin < seg_end; // this is important criteria when sect_size == 0
return seg_begin <= sect_begin && sect_begin < seg_end; // Example: seg_begin=10, seg_end=12 (-> covering the bytes 10 and 11)
} // sect_begin=12, sect_size=0 -> shall return false!
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------