Fix StreamingMemoryObject to respect known object size.
The existing code for method StreamingMemoryObject.fetchToPos does not respect
the corresonding call to setKnownObjectSize(). As a result, it allows the
StreamingMemoryObject to read bytes past the object size.
This patch provides a test case, and code to fix the problem.
Patch by Karl Schimpf
Differential Revision: http://reviews.llvm.org/D8931
llvm-svn: 237939
diff --git a/llvm/unittests/Support/StreamingMemoryObject.cpp b/llvm/unittests/Support/StreamingMemoryObject.cpp
index 2013649..c043efb 100644
--- a/llvm/unittests/Support/StreamingMemoryObject.cpp
+++ b/llvm/unittests/Support/StreamingMemoryObject.cpp
@@ -27,3 +27,12 @@
StreamingMemoryObject O(DS);
EXPECT_TRUE(O.isValidAddress(32 * 1024));
}
+
+TEST(StreamingMemoryObject, TestSetKnownObjectSize) {
+ auto *DS = new NullDataStreamer();
+ StreamingMemoryObject O(DS);
+ uint8_t Buf[32];
+ EXPECT_EQ((uint64_t) 16, O.readBytes(Buf, 16, 0));
+ O.setKnownObjectSize(24);
+ EXPECT_EQ((uint64_t) 8, O.readBytes(Buf, 16, 16));
+}