This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Do without union of variable length arrays.


On 2015-10-07 02:17, Chih-hung Hsieh wrote:
 > +    if (unlikely (phnum >
 > +                  SIZE_MAX / MAX (sizeof (Elf32_Phdr), sizeof 
(Elf64_Phdr))))
 > +      return DWFL_E_NOMEM;
 > +    const size_t phdrs_bytes =
 > +        phnum * MAX (sizeof (Elf32_Phdr), sizeof (Elf64_Phdr));
 > +    void *phdrs = malloc (phdrs_bytes);
 > +    Elf32_Phdr (*p32)[phnum] = phdrs;
 > +    Elf64_Phdr (*p64)[phnum] = phdrs;

If the amount of allocated memory is explicitly calculated as above it's 
potentially possible to use exact amount, e.g. phnum * sizeof 
(Elf32_Phdr) for p32 (and assign NULL to p64) or phnum * MAX (sizeof 
(Elf64_Phdr) for p64 (and assign NULL to p32). I'm not familiar with the 
codebase enough to judge if it's feasible. Just to make sure that this 
aspect is not overlooked.

-- 
Alexander Cherepanov

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]