Merge "Fix off by one error." am: 551efd11f7
am: efc71fde89

Change-Id: I9cfe5296ccbe8543579ad08070d9e3b346dd7b2d
diff --git a/libunwindstack/RegsInfo.h b/libunwindstack/RegsInfo.h
index e6dd33c..e445a91 100644
--- a/libunwindstack/RegsInfo.h
+++ b/libunwindstack/RegsInfo.h
@@ -41,7 +41,7 @@
   }
 
   inline AddressType* Save(uint32_t reg) {
-    if (reg > MAX_REGISTERS) {
+    if (reg >= MAX_REGISTERS) {
       // This should never happen since all currently supported
       // architectures have < 64 total registers.
       abort();
diff --git a/libunwindstack/tests/RegsInfoTest.cpp b/libunwindstack/tests/RegsInfoTest.cpp
index 052b5bf..a6bc2c5 100644
--- a/libunwindstack/tests/RegsInfoTest.cpp
+++ b/libunwindstack/tests/RegsInfoTest.cpp
@@ -82,4 +82,11 @@
   }
 }
 
+TEST(RegsInfoTest, invalid_register) {
+  RegsImplFake<uint64_t> regs(64);
+  RegsInfo<uint64_t> info(&regs);
+
+  EXPECT_DEATH(info.Save(RegsInfo<uint64_t>::MAX_REGISTERS), "");
+}
+
 }  // namespace unwindstack