diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-10-24 00:52:15 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-10-24 00:52:15 +0000 |
commit | fa2eceb99e7094f198dd5ea392f4acb1edc05769 (patch) | |
tree | 1760bdb822e69c438300f2618a5645b621e32fcf | |
parent | cdafe2bec7a26316ddaa6dab024a4977b169f670 (diff) | |
parent | bcd7738b013accb1c32e0681c1271e9f30946bac (diff) | |
download | unwinding-fa2eceb99e7094f198dd5ea392f4acb1edc05769.tar.gz |
Merge "Fix off by one error."
-rw-r--r-- | libunwindstack/RegsInfo.h | 2 | ||||
-rw-r--r-- | libunwindstack/tests/RegsInfoTest.cpp | 7 |
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(®s); + + EXPECT_DEATH(info.Save(RegsInfo<uint64_t>::MAX_REGISTERS), ""); +} + } // namespace unwindstack |