[SLOF] [PATCH slof 03/13] elf: Compile with -Wextra

Alexey Kardashevskiy aik at ozlabs.ru
Thu Jan 28 14:44:37 AEDT 2021



On 28/01/2021 14:41, Alexey Kardashevskiy wrote:
> 
> 
> On 28/01/2021 02:18, Thomas Huth wrote:
>> On 27/01/2021 09.57, Alexey Kardashevskiy wrote:
>>> -Wextra enables a bunch of rather useful checks which this fixes.
>>>
>>> Signed-off-by: Alexey Kardashevskiy <aik at ozlabs.ru>
>>> ---
>> [...]
>>> diff --git a/lib/libelf/elf32.c b/lib/libelf/elf32.c
>>> index 64ea386a96da..b213a6f9ca17 100644
>>> --- a/lib/libelf/elf32.c
>>> +++ b/lib/libelf/elf32.c
>>> @@ -212,13 +212,13 @@ elf_byteswap_header32(void *file_addr)
>>>    * file.
>>>    * @return Return -1 on error, size of file otherwise.
>>>    */
>>> -long elf_get_file_size32(const void *buffer, const long buffer_size)
>>> +long elf_get_file_size32(const void *buffer, const unsigned long 
>>> buffer_size)
>>>   {
>>>       const struct ehdr32 *ehdr = (const struct ehdr32 *) buffer;
>>>       const uint8_t *buffer_end = buffer + buffer_size;
>>>       const struct phdr32 *phdr;
>>>       const struct shdr32 *shdr;
>>> -    long elf_size = -1;
>>> +    unsigned long elf_size = -1;
>>
>> That looks kind of ugly, since the return type of the function is 
>> signed again later...
> 
> True.
> 
>> Maybe it's better to cast in the MAX() function instead?
> 
> gcc happily casts the result of "+" to a signed type.


ouch, no, never mind, there are actually more warnings to fix.


-- 
Alexey


More information about the SLOF mailing list