diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-06-01 18:13:06 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-06-01 18:13:06 +0000 |
commit | b6aa87510cdb206d00a6fec4842ef6bb794b11e6 (patch) | |
tree | 97aea3b6bc65e795feaf592b3564926628749a3f /llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp | |
parent | a7c29321bebe9a83ea3e49c4508921cc4e6b3580 (diff) | |
download | bcm5719-llvm-b6aa87510cdb206d00a6fec4842ef6bb794b11e6.tar.gz bcm5719-llvm-b6aa87510cdb206d00a6fec4842ef6bb794b11e6.zip |
[CodeView] Make sure StreamRef::readBytes doesn't read too much
llvm-svn: 271418
Diffstat (limited to 'llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp b/llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp index 03f2befaed5..aa579a3700a 100644 --- a/llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp +++ b/llvm/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp @@ -71,14 +71,14 @@ private: // Tests that a read which is entirely contained within a single block works // and does not allocate. -TEST(MappedBlockStreamTest, ZeroCopyReadNoBreak) { +TEST(MappedBlockStreamTest, ReadBeyondEndOfStreamRef) { DiscontiguousFile F; MappedBlockStream S(0, F); StreamReader R(S); - StringRef Str; - EXPECT_NO_ERROR(R.readFixedString(Str, 1)); - EXPECT_EQ(Str, StringRef("A")); - EXPECT_EQ(0U, S.getNumBytesCopied()); + StreamRef SR; + EXPECT_NO_ERROR(R.readStreamRef(SR, 0U)); + ArrayRef<uint8_t> Buffer; + EXPECT_ERROR(SR.readBytes(0U, 1U, Buffer)); } // Tests that a read which outputs into a full destination buffer works and @@ -162,4 +162,16 @@ TEST(MappedBlockStreamTest, InvalidReadSizeNonContiguousBreak) { EXPECT_EQ(0U, S.getNumBytesCopied()); } +// Tests that a read which is entirely contained within a single block but +// beyond the end of a StreamRef fails. +TEST(MappedBlockStreamTest, ZeroCopyReadNoBreak) { + DiscontiguousFile F; + MappedBlockStream S(0, F); + StreamReader R(S); + StringRef Str; + EXPECT_NO_ERROR(R.readFixedString(Str, 1)); + EXPECT_EQ(Str, StringRef("A")); + EXPECT_EQ(0U, S.getNumBytesCopied()); +} + } // end anonymous namespace |