Index: util/mac/mach_o_image_reader_test.cc |
diff --git a/util/mac/mach_o_image_reader_test.cc b/util/mac/mach_o_image_reader_test.cc |
index b0ea514361fdce1869dba0ad9beba14c2d480545..6fcfebf6d16573647208c078ed6cdc521871aef9 100644 |
--- a/util/mac/mach_o_image_reader_test.cc |
+++ b/util/mac/mach_o_image_reader_test.cc |
@@ -281,10 +281,38 @@ void ExpectSegmentCommands(const MachHeader* expect_image, |
// Similarly, make sure that a section name that exists in one segment isn’t |
// accidentally found during a lookup for that section in a different segment. |
- EXPECT_TRUE(actual_image->GetSectionByName(SEG_TEXT, SECT_TEXT, NULL)); |
+ // |
+ // If the image has no sections (unexpected), then any section lookup should |
+ // fail, and these initial values of test_segment and test_section are fine |
+ // for the EXPECT_FALSE checks on GetSectionByName() below. |
+ std::string test_segment = SEG_DATA; |
+ std::string test_section = SECT_TEXT; |
+ |
+ const process_types::section* section = |
+ actual_image->GetSectionAtIndex(1, NULL, NULL); |
+ if (section) { |
+ // Use the name of the first section in the image as the section that |
+ // shouldn’t appear in a different segment. If the first section is in the |
+ // __TEXT segment (as it is normally), then a section by the same name |
+ // wouldn’t be expected in the __DATA segment. But if the first section is |
+ // in any other segment, then it wouldn’t be expected in the __TEXT segment. |
+ if (MachOImageSegmentReader::SegmentNameString(section->segname) == |
+ SEG_TEXT) { |
Robert Sesek
2014/09/22 16:35:47
nit: indent +4
|
+ test_segment = SEG_DATA; |
+ } else { |
+ test_segment = SEG_TEXT; |
+ } |
+ test_section = |
+ MachOImageSegmentReader::SectionNameString(section->sectname); |
+ |
+ // It should be possible to look up the first section by name. |
+ EXPECT_EQ(section, actual_image->GetSectionByName( |
+ section->segname, section->sectname, NULL)); |
+ } |
+ EXPECT_FALSE( |
+ actual_image->GetSectionByName("NoSuchSegment", test_section, NULL)); |
EXPECT_FALSE( |
- actual_image->GetSectionByName("NoSuchSegment", SECT_TEXT, NULL)); |
- EXPECT_FALSE(actual_image->GetSectionByName(SEG_DATA, SECT_TEXT, NULL)); |
+ actual_image->GetSectionByName(test_segment, test_section, NULL)); |
// The __LINKEDIT segment normally does exist but doesn’t have any sections. |
EXPECT_FALSE( |