Commit 7c1cfd61 by Kimmo Kinnunen Committed by Shannon Woods

Make ShBuiltInResources comparable with memcmp

Chromium builds a std::map with ShBuiltInResources as part of the key. Comparator for == and < are needed for the map implementation. Currently Chromium uses memcmp as the comparator. Padding in ShBuiltInResources causes uninitialized reads. Fix this by clearing the padding with memset during ShBuiltInResources initialization. Change-Id: I78aa3c59ce165503831aa2a67c96cf8af316c152 Reviewed-on: https://chromium-review.googlesource.com/223431Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent 710e5775
...@@ -280,6 +280,8 @@ typedef struct ...@@ -280,6 +280,8 @@ typedef struct
// //
// Initialize built-in resources with minimum expected values. // Initialize built-in resources with minimum expected values.
// Parameters:
// resources: The object to initialize. Will be comparable with memcmp.
// //
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources); COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
......
...@@ -183,6 +183,9 @@ int ShFinalize() ...@@ -183,6 +183,9 @@ int ShFinalize()
// //
void ShInitBuiltInResources(ShBuiltInResources* resources) void ShInitBuiltInResources(ShBuiltInResources* resources)
{ {
// Make comparable.
memset(resources, 0, sizeof(*resources));
// Constants. // Constants.
resources->MaxVertexAttribs = 8; resources->MaxVertexAttribs = 8;
resources->MaxVertexUniformVectors = 128; resources->MaxVertexUniformVectors = 128;
......
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// API_test.cpp:
// Some tests for the compiler API.
//
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
TEST(APITest, CompareShBuiltInResources)
{
ShBuiltInResources a_resources;
memset(&a_resources, 88, sizeof(a_resources));
ShInitBuiltInResources(&a_resources);
ShBuiltInResources b_resources;
memset(&b_resources, 77, sizeof(b_resources));
ShInitBuiltInResources(&b_resources);
EXPECT_TRUE(memcmp(&a_resources, &b_resources, sizeof(a_resources)) == 0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment