[Mesa-dev,1/2] glinfo_common: fix extension_supported() function

Submitted by Brian Paul on June 9, 2014, 12:26 p.m.

Details

Message ID 1402316813-3867-1-git-send-email-brianp@vmware.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Brian Paul June 9, 2014, 12:26 p.m.
The code did not correctly handle super-string handling.  For example,
if we were searching for "WGL_ARB_pixel_format" but we found
"WGL_ARB_pixel_format_float" we'd stop searching and return 0.  Now
we search past that initial, incorrect match.
---
 src/xdemos/glinfo_common.c |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/xdemos/glinfo_common.c b/src/xdemos/glinfo_common.c
index e6517d7..e7ef508 100644
--- a/src/xdemos/glinfo_common.c
+++ b/src/xdemos/glinfo_common.c
@@ -306,12 +306,22 @@  build_core_profile_extension_list(const struct ext_functions *extfuncs)
 GLboolean
 extension_supported(const char *ext, const char *extensionsList)
 {
-   const char *p = strstr(extensionsList, ext);
-   if (p) {
-      /* check that next char is a space or end of string */
-      int extLen = strlen(ext);
-      if (p[extLen] == 0 || p[extLen] == ' ')
-         return 1;
+   while (1) {
+      const char *p = strstr(extensionsList, ext);
+      if (p) {
+         /* check that next char is a space or end of string */
+         int extLen = strlen(ext);
+         if (p[extLen] == 0 || p[extLen] == ' ') {
+            return 1;
+         }
+         else {
+            /* We found a superset string, keep looking */
+            extensionsList += extLen;
+         }
+      }
+      else {
+         break;
+      }
    }
    return 0;
 }

Comments

On 06/09/2014 05:26 AM, Brian Paul wrote:
> The code did not correctly handle super-string handling.  For example,
> if we were searching for "WGL_ARB_pixel_format" but we found
> "WGL_ARB_pixel_format_float" we'd stop searching and return 0.  Now
> we search past that initial, incorrect match.

This patch is

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>

> ---
>  src/xdemos/glinfo_common.c |   22 ++++++++++++++++------
>  1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/src/xdemos/glinfo_common.c b/src/xdemos/glinfo_common.c
> index e6517d7..e7ef508 100644
> --- a/src/xdemos/glinfo_common.c
> +++ b/src/xdemos/glinfo_common.c
> @@ -306,12 +306,22 @@ build_core_profile_extension_list(const struct ext_functions *extfuncs)
>  GLboolean
>  extension_supported(const char *ext, const char *extensionsList)
>  {
> -   const char *p = strstr(extensionsList, ext);
> -   if (p) {
> -      /* check that next char is a space or end of string */
> -      int extLen = strlen(ext);
> -      if (p[extLen] == 0 || p[extLen] == ' ')
> -         return 1;
> +   while (1) {
> +      const char *p = strstr(extensionsList, ext);
> +      if (p) {
> +         /* check that next char is a space or end of string */
> +         int extLen = strlen(ext);
> +         if (p[extLen] == 0 || p[extLen] == ' ') {
> +            return 1;
> +         }
> +         else {
> +            /* We found a superset string, keep looking */
> +            extensionsList += extLen;
> +         }
> +      }
> +      else {
> +         break;
> +      }
>     }
>     return 0;
>  }
>