angle: prevent huge allocations when GL_MAX_VERTEX_ATTRIBS fails
I'm not sure why yet, but when using angle in skia,
getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs) sometimes fails,
and when that happens we attempt to allocate and array with the size of
maxVertexAttribs, which is uninitialized, which could be huge.
Prevent this by initializing the variable.
Also sweep through other similar calls and ensure that these use
initialized values (test code has not been updated)
BUG=skia:4380
Change-Id: If1f3cf72f2b2829ad3933637af8778d574a20f61
Reviewed-on: https://chromium-review.googlesource.com/307239
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tryjob-Request: Jamie Madill <jmadill@chromium.org>
Tryjob-Request: Dian Xiang <dianx@google.com>
Tested-by: Hendrik Wagenaar <hendrikw@chromium.org>
diff --git a/src/libANGLE/queryconversions.cpp b/src/libANGLE/queryconversions.cpp
index 5633ce4..3a6059a 100644
--- a/src/libANGLE/queryconversions.cpp
+++ b/src/libANGLE/queryconversions.cpp
@@ -8,6 +8,8 @@
#include "libANGLE/queryconversions.h"
+#include <vector>
+
#include "libANGLE/Context.h"
#include "common/utilities.h"
@@ -101,59 +103,43 @@
{
if (nativeType == GL_INT)
{
- GLint *intParams = NULL;
- intParams = new GLint[numParams];
-
- context->getIntegerv(pname, intParams);
+ std::vector<GLint> intParams(numParams, 0);
+ context->getIntegerv(pname, intParams.data());
for (unsigned int i = 0; i < numParams; ++i)
{
outParams[i] = CastStateValue<QueryT>(pname, intParams[i]);
}
-
- delete [] intParams;
}
else if (nativeType == GL_BOOL)
{
- GLboolean *boolParams = NULL;
- boolParams = new GLboolean[numParams];
-
- context->getBooleanv(pname, boolParams);
+ std::vector<GLboolean> boolParams(numParams, GL_FALSE);
+ context->getBooleanv(pname, boolParams.data());
for (unsigned int i = 0; i < numParams; ++i)
{
outParams[i] = (boolParams[i] == GL_FALSE ? static_cast<QueryT>(0) : static_cast<QueryT>(1));
}
-
- delete [] boolParams;
}
else if (nativeType == GL_FLOAT)
{
- GLfloat *floatParams = NULL;
- floatParams = new GLfloat[numParams];
-
- context->getFloatv(pname, floatParams);
+ std::vector<GLfloat> floatParams(numParams, 0.0f);
+ context->getFloatv(pname, floatParams.data());
for (unsigned int i = 0; i < numParams; ++i)
{
outParams[i] = CastStateValue<QueryT>(pname, floatParams[i]);
}
-
- delete [] floatParams;
}
else if (nativeType == GL_INT_64_ANGLEX)
{
- GLint64 *int64Params = NULL;
- int64Params = new GLint64[numParams];
-
- context->getInteger64v(pname, int64Params);
+ std::vector<GLint64> int64Params(numParams, 0);
+ context->getInteger64v(pname, int64Params.data());
for (unsigned int i = 0; i < numParams; ++i)
{
outParams[i] = CastStateValue<QueryT>(pname, int64Params[i]);
}
-
- delete [] int64Params;
}
else UNREACHABLE();
}
diff --git a/src/libANGLE/renderer/gl/FunctionsGL.cpp b/src/libANGLE/renderer/gl/FunctionsGL.cpp
index bb85139..37e13a4 100644
--- a/src/libANGLE/renderer/gl/FunctionsGL.cpp
+++ b/src/libANGLE/renderer/gl/FunctionsGL.cpp
@@ -788,14 +788,11 @@
}
// Check the context profile
+ profile = 0;
if (isAtLeastGL(gl::Version(3, 2)))
{
getIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
}
- else
- {
- profile = 0;
- }
// clang-format off
diff --git a/src/libANGLE/renderer/gl/VertexArrayGL.cpp b/src/libANGLE/renderer/gl/VertexArrayGL.cpp
index 6227a51..7085663 100644
--- a/src/libANGLE/renderer/gl/VertexArrayGL.cpp
+++ b/src/libANGLE/renderer/gl/VertexArrayGL.cpp
@@ -50,7 +50,7 @@
mFunctions->genVertexArrays(1, &mVertexArrayID);
// Set the cached vertex attribute array size
- GLint maxVertexAttribs;
+ GLint maxVertexAttribs = 0;
mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
mAppliedAttributes.resize(maxVertexAttribs);
}
diff --git a/src/libANGLE/renderer/gl/renderergl_utils.cpp b/src/libANGLE/renderer/gl/renderergl_utils.cpp
index 508b28a..3988a0c 100644
--- a/src/libANGLE/renderer/gl/renderergl_utils.cpp
+++ b/src/libANGLE/renderer/gl/renderergl_utils.cpp
@@ -111,35 +111,35 @@
static GLint QuerySingleGLInt(const FunctionsGL *functions, GLenum name)
{
- GLint result;
+ GLint result = 0;
functions->getIntegerv(name, &result);
return result;
}
static GLint QueryGLIntRange(const FunctionsGL *functions, GLenum name, size_t index)
{
- GLint result[2];
+ GLint result[2] = {};
functions->getIntegerv(name, result);
return result[index];
}
static GLint64 QuerySingleGLInt64(const FunctionsGL *functions, GLenum name)
{
- GLint64 result;
+ GLint64 result = 0;
functions->getInteger64v(name, &result);
return result;
}
static GLfloat QuerySingleGLFloat(const FunctionsGL *functions, GLenum name)
{
- GLfloat result;
+ GLfloat result = 0.0f;
functions->getFloatv(name, &result);
return result;
}
static GLfloat QueryGLFloatRange(const FunctionsGL *functions, GLenum name, size_t index)
{
- GLfloat result[2];
+ GLfloat result[2] = {};
functions->getFloatv(name, result);
return result[index];
}