[Mesa-dev] [PATCH] mesa, st/glx, st/wgl: Move GL version validation into an helper.

Jose Fonseca jfonseca at vmware.com
Fri Nov 14 12:37:12 PST 2014


piglit didn't catch this but I just noticed there a bug. It should be:

diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index 5bdef16..3f08d31 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -472,8 +472,8 @@ _mesa_is_valid_version(int major, int minor)
       /* 4 . */ 5,
    };
 
-   return (major >= 0 &&
-           major < sizeof max_minor_version &&
+   return (major > 0 &&
+           major <= sizeof max_minor_version &&
            minor >= 0 &&
            minor <= max_minor_version[major - 1]);
 }
@@ -488,8 +488,8 @@ _mesa_is_valid_es_version(int major, int minor)
       /* 3 . */ 1,
    };
 
-   return (major >= 0 &&
-           major < sizeof max_minor_version &&
+   return (major > 0 &&
+           major <= sizeof max_minor_version &&
            minor >= 0 &&
            minor <= max_minor_version[major - 1]);
 }


________________________________________
From: mesa-dev <mesa-dev-bounces at lists.freedesktop.org> on behalf of jfonseca at vmware.com <jfonseca at vmware.com>
Sent: 14 November 2014 20:33
To: mesa-dev at lists.freedesktop.org; Brian Paul
Subject: [Mesa-dev] [PATCH] mesa, st/glx,       st/wgl: Move GL version validation into an helper.

From: José Fonseca <jfonseca at vmware.com>

As suggested by Brian Paul.

Tested with piglit glx-create-context-invalid-{gl,es}-version.
---
 src/gallium/state_trackers/glx/xlib/glx_api.c    | 13 +++-------
 src/gallium/state_trackers/wgl/stw_ext_context.c | 13 +++-------
 src/mesa/main/version.c                          | 33 ++++++++++++++++++++++++
 src/mesa/main/version.h                          |  6 +++++
 4 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c
index 1807edb..d4e028c 100644
--- a/src/gallium/state_trackers/glx/xlib/glx_api.c
+++ b/src/gallium/state_trackers/glx/xlib/glx_api.c
@@ -36,6 +36,8 @@
 #include <X11/Xmd.h>
 #include <GL/glxproto.h>

+#include "main/version.h"
+
 #include "xm_api.h"


@@ -2792,19 +2794,12 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
    if (majorVersion <= 0 ||
        minorVersion < 0 ||
        (profileMask != GLX_CONTEXT_ES_PROFILE_BIT_EXT &&
-        ((majorVersion == 1 && minorVersion > 5) ||
-         (majorVersion == 2 && minorVersion > 1) ||
-         (majorVersion == 3 && minorVersion > 3) ||
-         (majorVersion == 4 && minorVersion > 5) ||
-         majorVersion > 4))) {
+        !_mesa_is_valid_version(majorVersion, minorVersion))) {
       generate_error(dpy, BadMatch, 0, X_GLXCreateContextAtrribsARB, True);
       return NULL;
    }
    if (profileMask == GLX_CONTEXT_ES_PROFILE_BIT_EXT &&
-       ((majorVersion == 1 && minorVersion > 1) ||
-        (majorVersion == 2 && minorVersion > 0) ||
-        (majorVersion == 3 && minorVersion > 1) ||
-        majorVersion > 3)) {
+       !_mesa_is_valid_es_version(majorVersion, minorVersion)) {
       /* GLX_EXT_create_context_es2_profile says nothing to justifying a
        * different error code for invalid ES versions, but this is what NVIDIA
        * does and piglit expects.
diff --git a/src/gallium/state_trackers/wgl/stw_ext_context.c b/src/gallium/state_trackers/wgl/stw_ext_context.c
index 8a96cac..ee46334 100644
--- a/src/gallium/state_trackers/wgl/stw_ext_context.c
+++ b/src/gallium/state_trackers/wgl/stw_ext_context.c
@@ -30,6 +30,8 @@
 #include <GL/gl.h>
 #include <GL/wglext.h>

+#include "main/version.h"
+
 #include "stw_icd.h"
 #include "stw_context.h"
 #include "stw_device.h"
@@ -114,16 +116,9 @@ wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const int *attribList)
    if (majorVersion <= 0 ||
        minorVersion < 0 ||
        (profileMask != WGL_CONTEXT_ES_PROFILE_BIT_EXT &&
-        ((majorVersion == 1 && minorVersion > 5) ||
-         (majorVersion == 2 && minorVersion > 1) ||
-         (majorVersion == 3 && minorVersion > 3) ||
-         (majorVersion == 4 && minorVersion > 5) ||
-         majorVersion > 4)) ||
+        !_mesa_is_valid_version(majorVersion, minorVersion)) ||
        (profileMask == WGL_CONTEXT_ES_PROFILE_BIT_EXT &&
-        ((majorVersion == 1 && minorVersion > 1) ||
-         (majorVersion == 2 && minorVersion > 0) ||
-         (majorVersion == 3 && minorVersion > 1) ||
-         majorVersion > 3))) {
+        !_mesa_is_valid_es_version(majorVersion, minorVersion))) {
       SetLastError(ERROR_INVALID_VERSION_ARB);
       return NULL;
    }
diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index 4951891..5bdef16 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -460,3 +460,36 @@ _mesa_compute_version(struct gl_context *ctx)
       break;
    }
 }
+
+
+GLboolean
+_mesa_is_valid_version(int major, int minor)
+{
+   static const char max_minor_version[] = {
+      /* 1 . */ 5,
+      /* 2 . */ 1,
+      /* 3 . */ 3,
+      /* 4 . */ 5,
+   };
+
+   return (major >= 0 &&
+           major < sizeof max_minor_version &&
+           minor >= 0 &&
+           minor <= max_minor_version[major - 1]);
+}
+
+
+GLboolean
+_mesa_is_valid_es_version(int major, int minor)
+{
+   static const char max_minor_version[] = {
+      /* 1 . */ 1,
+      /* 2 . */ 0,
+      /* 3 . */ 1,
+   };
+
+   return (major >= 0 &&
+           major < sizeof max_minor_version &&
+           minor >= 0 &&
+           minor <= max_minor_version[major - 1]);
+}
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index 450a0e3..e2e1fc2 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -50,4 +50,10 @@ _mesa_override_glsl_version(struct gl_constants *consts);
 extern int
 _mesa_get_gl_version_override(void);

+extern GLboolean
+_mesa_is_valid_version(int major, int minor);
+
+extern GLboolean
+_mesa_is_valid_es_version(int major, int minor);
+
 #endif /* VERSION_H */
--
2.1.1

_______________________________________________
mesa-dev mailing list
mesa-dev at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list