diff options
author | Vladimir Levin <vmpstr@chromium.org> | 2017-11-15 12:01:51 -0800 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-15 20:25:42 +0000 |
commit | 70fb479ae6a311385be576f9b006fc5dc1ecdfd9 (patch) | |
tree | bf1e4aabf78fd91174f924cf71794511b803848c | |
parent | 559f556d9d70ef9d1202e436a56d48364b279ac6 (diff) |
Ensure that removing last extension from GrGLExtension doesn't assert.
This patch fixes an assert that triggers when removing the last
extension in the list, since the index operator goes out of bounds.
Added a test that fails without the code changes and passes with the
changes.
R=bsalomon@chromium.org
Change-Id: I0d561b150899c178f638dde088af773fddf112d9
Reviewed-on: https://skia-review.googlesource.com/72000
Commit-Queue: Vladimir Levin <vmpstr@chromium.org>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
-rw-r--r-- | gn/tests.gni | 1 | ||||
-rw-r--r-- | src/gpu/gl/GrGLExtensions.cpp | 6 | ||||
-rw-r--r-- | tests/GrGLExtensionsTest.cpp | 53 |
3 files changed, 58 insertions, 2 deletions
diff --git a/gn/tests.gni b/gn/tests.gni index 02cc45fcb1..6579820877 100644 --- a/gn/tests.gni +++ b/gn/tests.gni @@ -91,6 +91,7 @@ tests_sources = [ "$_tests/GrCCPRTest.cpp", "$_tests/GrContextAbandonTest.cpp", "$_tests/GrContextFactoryTest.cpp", + "$_tests/GrGLExtensionsTest.cpp", "$_tests/GrMemoryPoolTest.cpp", "$_tests/GrMeshTest.cpp", "$_tests/GrMipMappedTest.cpp", diff --git a/src/gpu/gl/GrGLExtensions.cpp b/src/gpu/gl/GrGLExtensions.cpp index c4f6475293..c584ad78a9 100644 --- a/src/gpu/gl/GrGLExtensions.cpp +++ b/src/gpu/gl/GrGLExtensions.cpp @@ -131,8 +131,10 @@ bool GrGLExtensions::remove(const char ext[]) { // This is not terribly effecient but we really only expect this function to be called at // most a handful of times when our test programs start. fStrings->removeShuffle(idx); - SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; - SkTInsertionSort(&(fStrings->operator[](idx)), &fStrings->back(), cmp); + if (idx != fStrings->count()) { + SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; + SkTInsertionSort(&(fStrings->operator[](idx)), &fStrings->back(), cmp); + } return true; } diff --git a/tests/GrGLExtensionsTest.cpp b/tests/GrGLExtensionsTest.cpp new file mode 100644 index 0000000000..70620764cb --- /dev/null +++ b/tests/GrGLExtensionsTest.cpp @@ -0,0 +1,53 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkTypes.h" + +// This test is a GPU-backend specific test. +#if SK_SUPPORT_GPU + +#include "gl/GrGLDefines.h" +#include "gl/GrGLExtensions.h" +#include "Test.h" + +const GrGLubyte* simpleGetString(GrGLenum name) { + return (const GrGLubyte*)(name == GR_GL_VERSION ? "3.0" : ""); +} + +void simpleGetIntegerv(GrGLenum name, GrGLint* params) { + if (name == GR_GL_NUM_EXTENSIONS) { + *params = 2; + } else { + *params = 0; + } +} + +const GrGLubyte* simpleGetStringi(GrGLenum name, GrGLuint index) { + if (name != GR_GL_EXTENSIONS || index >= 2) + return (const GrGLubyte*)""; + return (const GrGLubyte*)(index == 0 ? "test_extension_1" : "test_extension_2"); +} + +DEF_TEST(GrGLExtensionsTest_remove, reporter) { + GrGLExtensions ext; + ext.init(kNone_GrGLStandard, + &simpleGetString, + &simpleGetStringi, + &simpleGetIntegerv, + nullptr, + nullptr); + + REPORTER_ASSERT(reporter, ext.isInitialized()); + REPORTER_ASSERT(reporter, ext.has("test_extension_1")); + REPORTER_ASSERT(reporter, ext.has("test_extension_2")); + REPORTER_ASSERT(reporter, ext.remove("test_extension_2")); + REPORTER_ASSERT(reporter, !ext.has("test_extension_2")); + REPORTER_ASSERT(reporter, ext.remove("test_extension_1")); + REPORTER_ASSERT(reporter, !ext.has("test_extension_1")); +} + +#endif |