summaryrefslogtreecommitdiff
path: root/libunwindstack
diff options
context:
space:
mode:
authorFlorian Mayer <fmayer@google.com>2018-10-23 14:09:48 +0100
committerFlorian Mayer <fmayer@google.com>2018-10-23 18:10:41 +0100
commitbcd7738b013accb1c32e0681c1271e9f30946bac (patch)
treebe9eb0009e2b495ae02dd0900d3c1a820f676f87 /libunwindstack
parent99e9621c82c0baff42d71f90b88ce1b636821b97 (diff)
downloadunwinding-bcd7738b013accb1c32e0681c1271e9f30946bac.tar.gz
Fix off by one error.
Change-Id: I18a2d177f3212626b7091150f42dfe151e47570e
Diffstat (limited to 'libunwindstack')
-rw-r--r--libunwindstack/RegsInfo.h2
-rw-r--r--libunwindstack/tests/RegsInfoTest.cpp7
2 files changed, 8 insertions, 1 deletions
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 @@ struct RegsInfo {
}
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, all) {
}
}
+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