}
// Read section headers
- f.Sections = make([]*Section, shnum)
- names := make([]uint32, shnum)
+ c := saferio.SliceCap((*Section)(nil), uint64(shnum))
+ if c < 0 {
+ return nil, &FormatError{0, "too many sections", shnum}
+ }
+ f.Sections = make([]*Section, 0, c)
+ names := make([]uint32, 0, c)
for i := 0; i < shnum; i++ {
off := shoff + int64(i)*int64(shentsize)
sr.Seek(off, seekStart)
if err := binary.Read(sr, f.ByteOrder, sh); err != nil {
return nil, err
}
- names[i] = sh.Name
+ names = append(names, sh.Name)
s.SectionHeader = SectionHeader{
Type: SectionType(sh.Type),
Flags: SectionFlag(sh.Flags),
if err := binary.Read(sr, f.ByteOrder, sh); err != nil {
return nil, err
}
- names[i] = sh.Name
+ names = append(names, sh.Name)
s.SectionHeader = SectionHeader{
Type: SectionType(sh.Type),
Flags: SectionFlag(sh.Flags),
}
}
- f.Sections[i] = s
+ f.Sections = append(f.Sections, s)
}
if len(f.Sections) == 0 {