aboutsummaryrefslogtreecommitdiff
path: root/src/processor
diff options
context:
space:
mode:
authorSiyangXie@gmail.com <SiyangXie@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-09-15 01:11:34 +0000
committerSiyangXie@gmail.com <SiyangXie@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-09-15 01:11:34 +0000
commitb5b5f9e5205b7d31a401f245cdad44080cd7bfc9 (patch)
tree6dd1c60b9139564752d1146972c668d8b6a827fa /src/processor
parentFix a handful of comment spelling errors (Issue 385) (diff)
downloadbreakpad-b5b5f9e5205b7d31a401f245cdad44080cd7bfc9.tar.xz
Fix a bug in range_map-inl.h and add a unittest to expose the exisiting bug.
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@683 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/processor')
-rw-r--r--src/processor/range_map-inl.h2
-rw-r--r--src/processor/range_map_unittest.cc42
2 files changed, 43 insertions, 1 deletions
diff --git a/src/processor/range_map-inl.h b/src/processor/range_map-inl.h
index e7bf4512..3aa2603a 100644
--- a/src/processor/range_map-inl.h
+++ b/src/processor/range_map-inl.h
@@ -184,7 +184,7 @@ bool RangeMap<AddressType, EntryType>::RetrieveRangeAtIndex(
*entry = iterator->second.entry();
if (entry_base)
- *entry_base = iterator->first;
+ *entry_base = iterator->second.base();
if (entry_size)
*entry_size = iterator->first - iterator->second.base() + 1;
diff --git a/src/processor/range_map_unittest.cc b/src/processor/range_map_unittest.cc
index dd713fba..88e93be4 100644
--- a/src/processor/range_map_unittest.cc
+++ b/src/processor/range_map_unittest.cc
@@ -325,6 +325,43 @@ static bool RetrieveIndexTest(TestMap *range_map, int set) {
return true;
}
+// Additional RetriveAtIndex test to expose the bug in RetrieveRangeAtIndex().
+// Bug info: RetrieveRangeAtIndex() previously retrieves the high address of
+// entry, however, it is supposed to retrieve the base address of entry as
+// stated in the comment in range_map.h.
+static bool RetriveAtIndexTest2() {
+ scoped_ptr<TestMap> range_map(new TestMap());
+
+ // Store ranges with base address = 2 * object_id:
+ const int range_size = 2;
+ for (int object_id = 0; object_id < 100; ++object_id) {
+ linked_ptr<CountedObject> object(new CountedObject(object_id));
+ int base_address = 2 * object_id;
+ range_map->StoreRange(base_address, range_size, object);
+ }
+
+ linked_ptr<CountedObject> object;
+ int object_count = range_map->GetCount();
+ for (int object_index = 0; object_index < object_count; ++object_index) {
+ AddressType base;
+ if (!range_map->RetrieveRangeAtIndex(object_index, &object, &base, NULL)) {
+ fprintf(stderr, "FAILED: RetrieveAtIndexTest2 index %d, "
+ "expected success, observed failure\n", object_index);
+ return false;
+ }
+
+ int expected_base = 2 * object->id();
+ if (base != expected_base) {
+ fprintf(stderr, "FAILED: RetriveAtIndexTest2 index %d, "
+ "expected base %d, observed base %d",
+ object_index, expected_base, base);
+ return false;
+ }
+ }
+
+ return true;
+}
+
// RunTests runs a series of test sets.
static bool RunTests() {
@@ -497,6 +534,11 @@ static bool RunTests() {
}
}
+ if (!RetriveAtIndexTest2()) {
+ fprintf(stderr, "FAILED: did not pass RetrieveAtIndexTest2()\n");
+ return false;
+ }
+
return true;
}