OSDN Git Service

Fix parsing the EGL extension string.
authorNicolas Capens <capn@google.com>
Fri, 30 Oct 2015 16:55:21 +0000 (12:55 -0400)
committerNicolas Capens <capn@google.com>
Mon, 9 Nov 2015 20:31:59 +0000 (15:31 -0500)
The EGL extension string does not necessarily have a space before the
terminating null. The previous code would skip the last extension name
when there's no extra space. The new code also works for empty strings.

Change-Id: Ib272cf05a7ebcc0de417f91966489ed4db33c283

opengl/libs/EGL/egl_display.cpp

index 67edcf3..ab21c8f 100644 (file)
@@ -178,25 +178,21 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
 
         mExtensionString.setTo(gBuiltinExtensionString);
         char const* start = gExtensionString;
-        char const* end;
         do {
-            // find the space separating this extension for the next one
-            end = strchr(start, ' ');
-            if (end) {
-                // length of the extension string
-                const size_t len = end - start;
-                if (len) {
-                    // NOTE: we could avoid the copy if we had strnstr.
-                    const String8 ext(start, len);
-                    if (findExtension(disp.queryString.extensions, ext.string(),
-                            len)) {
-                        mExtensionString.append(start, len+1);
-                    }
+            // length of the extension name
+            size_t len = strcspn(start, " ");
+            if (len) {
+                // NOTE: we could avoid the copy if we had strnstr.
+                const String8 ext(start, len);
+                if (findExtension(disp.queryString.extensions, ext.string(),
+                        len)) {
+                    mExtensionString.append(ext + " ");
                 }
-                // process the next extension string, and skip the space.
-                start = end + 1;
+                // advance to the next extension name, skipping the space.
+                start += len;
+                start += (*start == ' ') ? 1 : 0;
             }
-        } while (end);
+        } while (*start != '\0');
 
         egl_cache_t::get()->initialize(this);