summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-05 16:12:39 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-05 16:12:39 +0000
commit9b6532995f9ca0f25c1b262469a94f9ea82c409b (patch)
treec54fc0bd62be858eef8fb43906c0ac7b87cb4d07 /gpu
parentfd36e4ed7d4adb48df2b4b208d86467ea1d20f87 (diff)
downloadchromium_src-9b6532995f9ca0f25c1b262469a94f9ea82c409b.zip
chromium_src-9b6532995f9ca0f25c1b262469a94f9ea82c409b.tar.gz
chromium_src-9b6532995f9ca0f25c1b262469a94f9ea82c409b.tar.bz2
Make FencedAlloctor fail on size = 0
BUG=none R=piman@chromium.org Review URL: https://chromiumcodereview.appspot.com/11419280 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/client/fenced_allocator.cc8
-rw-r--r--gpu/command_buffer/client/fenced_allocator_test.cc17
2 files changed, 22 insertions, 3 deletions
diff --git a/gpu/command_buffer/client/fenced_allocator.cc b/gpu/command_buffer/client/fenced_allocator.cc
index d262115..0d395c4 100644
--- a/gpu/command_buffer/client/fenced_allocator.cc
+++ b/gpu/command_buffer/client/fenced_allocator.cc
@@ -39,9 +39,11 @@ FencedAllocator::~FencedAllocator() {
// optimizing what to wait for, just looks inside the block in order (first-fit
// as well).
FencedAllocator::Offset FencedAllocator::Alloc(unsigned int size) {
- // Similarly to malloc, an allocation of 0 allocates at least 1 byte, to
- // return different pointers every time.
- if (size == 0) size = 1;
+ // size of 0 is not allowed because it would be inconsistent to only sometimes
+ // have it succeed. Example: Alloc(SizeOfBuffer), Alloc(0).
+ if (size == 0) {
+ return kInvalidOffset;
+ }
// Try first to allocate in a free block.
for (unsigned int i = 0; i < blocks_.size(); ++i) {
diff --git a/gpu/command_buffer/client/fenced_allocator_test.cc b/gpu/command_buffer/client/fenced_allocator_test.cc
index 381237b..44fb851 100644
--- a/gpu/command_buffer/client/fenced_allocator_test.cc
+++ b/gpu/command_buffer/client/fenced_allocator_test.cc
@@ -126,6 +126,14 @@ TEST_F(FencedAllocatorTest, TestBasic) {
EXPECT_TRUE(allocator_->CheckConsistency());
}
+// Test alloc 0 fails.
+TEST_F(FencedAllocatorTest, TestAllocZero) {
+ FencedAllocator::Offset offset = allocator_->Alloc(0);
+ EXPECT_EQ(FencedAllocator::kInvalidOffset, offset);
+ EXPECT_FALSE(allocator_->InUse());
+ EXPECT_TRUE(allocator_->CheckConsistency());
+}
+
// Checks out-of-memory condition.
TEST_F(FencedAllocatorTest, TestOutOfMemory) {
EXPECT_TRUE(allocator_->CheckConsistency());
@@ -446,6 +454,15 @@ TEST_F(FencedAllocatorWrapperTest, TestBasic) {
allocator_->Free(pointer_uint);
}
+// Test alloc 0 fails.
+TEST_F(FencedAllocatorWrapperTest, TestAllocZero) {
+ allocator_->CheckConsistency();
+
+ void *pointer = allocator_->Alloc(0);
+ ASSERT_FALSE(pointer);
+ EXPECT_TRUE(allocator_->CheckConsistency());
+}
+
// Checks out-of-memory condition.
TEST_F(FencedAllocatorWrapperTest, TestOutOfMemory) {
allocator_->CheckConsistency();