Fix 64-bit build failures.
Update the BufferStorage classes to use size_t for all sizes and offsets.
BufferStorage9 now uses a std::vector to manage its memory.
BUG=angle:631
Change-Id: Iea4e7b33ede59a5b9c6a1245690c4b7865096fc3
Reviewed-on: https://chromium-review.googlesource.com/197819
Reviewed-by: Nicolas Capens <nicolascapens@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2.gypi b/src/libGLESv2.gypi
index 56a921d..2b6e051 100644
--- a/src/libGLESv2.gypi
+++ b/src/libGLESv2.gypi
@@ -77,21 +77,15 @@
[
'ANGLE_ENABLE_D3D11',
],
- 'configurations':
+ 'msvs_settings':
{
- 'Debug':
+ 'VCLinkerTool':
{
- 'msvs_settings':
- {
- 'VCLinkerTool':
- {
- 'AdditionalDependencies':
- [
- 'dxguid.lib',
- ]
- }
- },
- }
+ 'AdditionalDependencies':
+ [
+ 'dxguid.lib',
+ ],
+ },
},
}],
],
diff --git a/src/libGLESv2/libGLESv2.cpp b/src/libGLESv2/libGLESv2.cpp
index fe8002b..8e2c42e 100644
--- a/src/libGLESv2/libGLESv2.cpp
+++ b/src/libGLESv2/libGLESv2.cpp
@@ -644,7 +644,13 @@
return gl::error(GL_INVALID_OPERATION);
}
- if ((size_t)size + offset > buffer->size())
+ // Check for possible overflow of size + offset
+ if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
+ {
+ return gl::error(GL_OUT_OF_MEMORY);
+ }
+
+ if (size + offset > buffer->size())
{
return gl::error(GL_INVALID_VALUE);
}
diff --git a/src/libGLESv2/renderer/BufferStorage.h b/src/libGLESv2/renderer/BufferStorage.h
index c057b63..a5f95d1 100644
--- a/src/libGLESv2/renderer/BufferStorage.h
+++ b/src/libGLESv2/renderer/BufferStorage.h
@@ -22,12 +22,11 @@
// The data returned is only guaranteed valid until next non-const method.
virtual void *getData() = 0;
- virtual void setData(const void* data, unsigned int size, unsigned int offset) = 0;
- virtual void copyData(BufferStorage* sourceStorage, unsigned int size,
- unsigned int sourceOffset, unsigned int destOffset) = 0;
+ virtual void setData(const void* data, size_t size, size_t offset) = 0;
+ virtual void copyData(BufferStorage* sourceStorage, size_t size, size_t sourceOffset, size_t destOffset) = 0;
virtual void clear() = 0;
virtual void markTransformFeedbackUsage() = 0;
- virtual unsigned int getSize() const = 0;
+ virtual size_t getSize() const = 0;
virtual bool supportsDirectBinding() const = 0;
unsigned int getSerial() const;
diff --git a/src/libGLESv2/renderer/VertexBuffer.cpp b/src/libGLESv2/renderer/VertexBuffer.cpp
index 3386b68..8adfb5b 100644
--- a/src/libGLESv2/renderer/VertexBuffer.cpp
+++ b/src/libGLESv2/renderer/VertexBuffer.cpp
@@ -177,7 +177,7 @@
unsigned int outputElementSize;
getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
- alignment = std::min(static_cast<size_t>(outputElementSize), 4u);
+ alignment = std::min<size_t>(outputElementSize, 4);
requiresConversion = (mRenderer->getVertexConversionType(vertexFormat) & VERTEX_CONVERT_CPU) != 0;
}
diff --git a/src/libGLESv2/renderer/d3d11/BufferStorage11.cpp b/src/libGLESv2/renderer/d3d11/BufferStorage11.cpp
index f5b6b4d..220726f 100644
--- a/src/libGLESv2/renderer/d3d11/BufferStorage11.cpp
+++ b/src/libGLESv2/renderer/d3d11/BufferStorage11.cpp
@@ -204,7 +204,7 @@
return mResolvedData.data();
}
-void BufferStorage11::setData(const void* data, unsigned int size, unsigned int offset)
+void BufferStorage11::setData(const void* data, size_t size, size_t offset)
{
size_t requiredSize = size + offset;
mSize = std::max(mSize, requiredSize);
@@ -239,8 +239,7 @@
}
}
-void BufferStorage11::copyData(BufferStorage* sourceStorage, unsigned int size,
- unsigned int sourceOffset, unsigned int destOffset)
+void BufferStorage11::copyData(BufferStorage* sourceStorage, size_t size, size_t sourceOffset, size_t destOffset)
{
BufferStorage11* sourceStorage11 = makeBufferStorage11(sourceStorage);
if (sourceStorage11)
@@ -258,7 +257,7 @@
dest->setDataRevision(dest->getDataRevision() + 1);
}
- mSize = std::max(mSize, destOffset + size);
+ mSize = std::max<size_t>(mSize, destOffset + size);
}
}
@@ -274,7 +273,7 @@
transformFeedbackStorage->setDataRevision(transformFeedbackStorage->getDataRevision() + 1);
}
-unsigned int BufferStorage11::getSize() const
+size_t BufferStorage11::getSize() const
{
return mSize;
}
diff --git a/src/libGLESv2/renderer/d3d11/BufferStorage11.h b/src/libGLESv2/renderer/d3d11/BufferStorage11.h
index 59c5a5f..7934de1 100644
--- a/src/libGLESv2/renderer/d3d11/BufferStorage11.h
+++ b/src/libGLESv2/renderer/d3d11/BufferStorage11.h
@@ -53,12 +53,11 @@
static BufferStorage11 *makeBufferStorage11(BufferStorage *bufferStorage);
virtual void *getData();
- virtual void setData(const void* data, unsigned int size, unsigned int offset);
- virtual void copyData(BufferStorage* sourceStorage, unsigned int size,
- unsigned int sourceOffset, unsigned int destOffset);
+ virtual void setData(const void* data, size_t size, size_t offset);
+ virtual void copyData(BufferStorage* sourceStorage, size_t size, size_t sourceOffset, size_t destOffset);
virtual void clear();
virtual void markTransformFeedbackUsage();
- virtual unsigned int getSize() const;
+ virtual size_t getSize() const;
virtual bool supportsDirectBinding() const;
ID3D11Buffer *getBuffer(BufferUsage usage);
diff --git a/src/libGLESv2/renderer/d3d9/BufferStorage9.cpp b/src/libGLESv2/renderer/d3d9/BufferStorage9.cpp
index 5f0ef75..f82d856 100644
--- a/src/libGLESv2/renderer/d3d9/BufferStorage9.cpp
+++ b/src/libGLESv2/renderer/d3d9/BufferStorage9.cpp
@@ -14,15 +14,12 @@
{
BufferStorage9::BufferStorage9()
+ : mSize(0)
{
- mMemory = NULL;
- mAllocatedSize = 0;
- mSize = 0;
}
BufferStorage9::~BufferStorage9()
{
- SafeDeleteArray(mMemory);
}
BufferStorage9 *BufferStorage9::makeBufferStorage9(BufferStorage *bufferStorage)
@@ -33,43 +30,29 @@
void *BufferStorage9::getData()
{
- return mMemory;
+ return mMemory.data();
}
-void BufferStorage9::setData(const void* data, unsigned int size, unsigned int offset)
+void BufferStorage9::setData(const void* data, size_t size, size_t offset)
{
- if (!mMemory || offset + size > mAllocatedSize)
+ if (offset + size > mMemory.size())
{
- unsigned int newAllocatedSize = offset + size;
- void *newMemory = new char[newAllocatedSize];
-
- if (offset > 0 && mMemory && mAllocatedSize > 0)
- {
- memcpy(newMemory, mMemory, std::min(offset, mAllocatedSize));
- }
-
- delete[] mMemory;
- mMemory = newMemory;
- mAllocatedSize = newAllocatedSize;
+ mMemory.resize(offset + size);
}
mSize = std::max(mSize, offset + size);
if (data)
{
- memcpy(reinterpret_cast<char*>(mMemory) + offset, data, size);
+ memcpy(mMemory.data() + offset, data, size);
}
}
-void BufferStorage9::copyData(BufferStorage* sourceStorage, unsigned int size,
- unsigned int sourceOffset, unsigned int destOffset)
+void BufferStorage9::copyData(BufferStorage* sourceStorage, size_t size, size_t sourceOffset, size_t destOffset)
{
BufferStorage9* source = makeBufferStorage9(sourceStorage);
if (source)
{
- void* sourceMemory = reinterpret_cast<char*>(source->mMemory) + sourceOffset;
- void* destMemory = reinterpret_cast<char*>(mMemory) + destOffset;
-
- memcpy(destMemory, sourceMemory, size);
+ memcpy(mMemory.data() + destOffset, source->mMemory.data() + sourceOffset, size);
}
}
@@ -83,7 +66,7 @@
UNREACHABLE();
}
-unsigned int BufferStorage9::getSize() const
+size_t BufferStorage9::getSize() const
{
return mSize;
}
diff --git a/src/libGLESv2/renderer/d3d9/BufferStorage9.h b/src/libGLESv2/renderer/d3d9/BufferStorage9.h
index 07ceb37..dd61624 100644
--- a/src/libGLESv2/renderer/d3d9/BufferStorage9.h
+++ b/src/libGLESv2/renderer/d3d9/BufferStorage9.h
@@ -23,12 +23,11 @@
static BufferStorage9 *makeBufferStorage9(BufferStorage *bufferStorage);
virtual void *getData();
- virtual void setData(const void* data, unsigned int size, unsigned int offset);
- virtual void copyData(BufferStorage* sourceStorage, unsigned int size,
- unsigned int sourceOffset, unsigned int destOffset);
+ virtual void setData(const void* data, size_t size, size_t offset);
+ virtual void copyData(BufferStorage* sourceStorage, size_t size, size_t sourceOffset, size_t destOffset);
virtual void clear();
virtual void markTransformFeedbackUsage();
- virtual unsigned int getSize() const;
+ virtual size_t getSize() const;
virtual bool supportsDirectBinding() const;
virtual bool isMapped() const;
@@ -38,10 +37,8 @@
private:
DISALLOW_COPY_AND_ASSIGN(BufferStorage9);
- void *mMemory;
- unsigned int mAllocatedSize;
-
- unsigned int mSize;
+ std::vector<char> mMemory;
+ size_t mSize;
};
}