aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-08 16:06:28 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-08 16:06:28 +0000
commita22407283650ae570d8f93db0f4f6df266812716 (patch)
treef023613ad346d5ee86188fbc45669c11cf2fe92c
parent9cd1ef54a6ac2761bde0fa6e3df99fc8a90e5193 (diff)
Make extension string parsing robust.
Review URL: https://codereview.chromium.org/12564003 git-svn-id: http://skia.googlecode.com/svn/trunk@8040 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--src/gpu/gl/GrGLExtensions.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/gpu/gl/GrGLExtensions.cpp b/src/gpu/gl/GrGLExtensions.cpp
index 2d8741479b..a28636ba1b 100644
--- a/src/gpu/gl/GrGLExtensions.cpp
+++ b/src/gpu/gl/GrGLExtensions.cpp
@@ -51,27 +51,20 @@ bool GrGLExtensions::init(GrGLBinding binding,
if (NULL == extensions) {
return false;
}
- // First count the extensions so that we don't cause the array to malloc multiple times.
- int extensionCnt = 1;
- const char* e = (const char*) extensions;
- while (NULL != (e = strchr(e+1, ' '))) {
- e += 1;
- ++extensionCnt;
- }
- fStrings.push_back_n(extensionCnt);
-
- int i = 0;
while (true) {
- size_t length = strcspn(extensions, " ");
- GrAssert(i < extensionCnt);
- fStrings[i].set(extensions, length);
- ++i;
- if ('\0' == extensions[length]) {
+ // skip over multiple spaces between extensions
+ while (' ' == *extensions) {
+ ++extensions;
+ }
+ // quit once we reach the end of the string.
+ if ('\0' == *extensions) {
break;
}
- extensions += length + 1;
+ // we found an extension
+ size_t length = strcspn(extensions, " ");
+ fStrings.push_back().set(extensions, length);
+ extensions += length;
}
- GrAssert(i == extensionCnt);
}
SkTSearchCompareLTFunctor<SkString, extension_compare> cmp;
SkTQSort(&fStrings.front(), &fStrings.back(), cmp);