From b5bf686b58a8692726e4017c734f0c6d065e5ac5 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Mon, 30 Jun 2014 10:30:00 +0000 Subject: [PATCH] MachO: stop iterating past the end of an array When trying to map atom types to sections, we were iterating through an array until we hit a sentinel value. There's no need for such dances when range-based for loops are available. llvm-svn: 212035 --- .../ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp | 15 +++++++-------- lld/test/mach-o/write-final-sections.yaml | 7 +------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index 5bc1b3d..67ed62c 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -227,9 +227,8 @@ const MachOFinalSectionFromAtomType sectsToAtomType[] = { SectionInfo *Util::getFinalSection(DefinedAtom::ContentType atomType) { - for (const MachOFinalSectionFromAtomType *p = sectsToAtomType ; - p->atomType != DefinedAtom::typeUnknown; ++p) { - if (p->atomType != atomType) + for (auto &p : sectsToAtomType) { + if (p.atomType != atomType) continue; SectionAttr sectionAttrs = 0; switch (atomType) { @@ -243,15 +242,15 @@ SectionInfo *Util::getFinalSection(DefinedAtom::ContentType atomType) { // If we already have a SectionInfo with this name, re-use it. // This can happen if two ContentType map to the same mach-o section. for (auto sect : _sectionMap) { - if (sect.second->sectionName.equals(p->sectionName) && - sect.second->segmentName.equals(p->segmentName)) { + if (sect.second->sectionName.equals(p.sectionName) && + sect.second->segmentName.equals(p.segmentName)) { return sect.second; } } // Otherwise allocate new SectionInfo object. - SectionInfo *sect = new (_allocator) SectionInfo(p->segmentName, - p->sectionName, - p->sectionType, + SectionInfo *sect = new (_allocator) SectionInfo(p.segmentName, + p.sectionName, + p.sectionType, sectionAttrs); _sectionInfos.push_back(sect); _sectionMap[atomType] = sect; diff --git a/lld/test/mach-o/write-final-sections.yaml b/lld/test/mach-o/write-final-sections.yaml index 81e9f32..2f8ddca 100644 --- a/lld/test/mach-o/write-final-sections.yaml +++ b/lld/test/mach-o/write-final-sections.yaml @@ -7,15 +7,10 @@ defined-atoms: - name: _foo scope: global content: [ 55 ] -# More for __TEXT, __text (with typeResolver) - - name: _resolver - scope: global - type: resolver - content: [ C3 ] # CHECK: Name: __text # CHECK: Segment: __TEXT # CHECK: SectionData ( -# CHECK-NEXT: 0000: 55C3 +# CHECK-NEXT: 0000: 55 # CHECK-NEXT: ) # For __TEXT, __const (with typeConstant), -- 2.7.4