From e64ab100593ab3caa6fc466d0c17a75859d7f88c Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Thu, 5 Mar 2015 22:22:22 +0100 Subject: [PATCH] Fix DataNodeView: Only allow read access to data region --- implementations/onblocks/datanodestore/DataNodeView.h | 11 ----------- .../onblocks/datanodestore/DataNodeViewTest.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/implementations/onblocks/datanodestore/DataNodeView.h b/implementations/onblocks/datanodestore/DataNodeView.h index 892139cc..558f559b 100644 --- a/implementations/onblocks/datanodestore/DataNodeView.h +++ b/implementations/onblocks/datanodestore/DataNodeView.h @@ -94,23 +94,12 @@ public: return GetOffset(); } - template - Entry *DataBegin() { - return const_cast(const_cast(this)->DataBegin()); - } - template const Entry *DataEnd() const { const unsigned int NUM_ENTRIES = layout().datasizeBytes() / sizeof(Entry); return DataBegin() + NUM_ENTRIES; } - template - Entry *DataEnd() { - return const_cast(const_cast(this)->DataEnd()); - } - - DataNodeLayout layout() const { return DataNodeLayout(_block->size()); } diff --git a/test/implementations/onblocks/datanodestore/DataNodeViewTest.cpp b/test/implementations/onblocks/datanodestore/DataNodeViewTest.cpp index 44260a83..dc8dbb88 100644 --- a/test/implementations/onblocks/datanodestore/DataNodeViewTest.cpp +++ b/test/implementations/onblocks/datanodestore/DataNodeViewTest.cpp @@ -63,10 +63,10 @@ TEST_F(DataNodeViewTest, DataIsStored) { auto key = block->key(); { DataNodeView view(std::move(block)); - std::memcpy(view.DataBegin(), randomData.data(), randomData.size()); + view.write(randomData.data(), 0, randomData.size()); } DataNodeView view(blockStore->load(key)); - EXPECT_EQ(0, std::memcmp(view.DataBegin(), randomData.data(), randomData.size())); + EXPECT_EQ(0, std::memcmp(view.data(), randomData.data(), randomData.size())); } TEST_F(DataNodeViewTest, HeaderAndBodyDontOverlap) { @@ -77,12 +77,12 @@ TEST_F(DataNodeViewTest, HeaderAndBodyDontOverlap) { DataNodeView view(std::move(block)); view.setDepth(3); view.setSize(1000000000u); - std::memcpy(view.DataBegin(), randomData.data(), DATASIZE_BYTES); + view.write(randomData.data(), 0, DATASIZE_BYTES); } DataNodeView view(blockStore->load(key)); EXPECT_EQ(3, view.Depth()); EXPECT_EQ(1000000000u, view.Size()); - EXPECT_EQ(0, std::memcmp(view.DataBegin(), randomData.data(), DATASIZE_BYTES)); + EXPECT_EQ(0, std::memcmp(view.data(), randomData.data(), DATASIZE_BYTES)); } TEST_F(DataNodeViewTest, DataBeginWorksWithOneByteEntries) {