[Mesa-dev] [PATCH] EGL: Fix some errors in eglDebugMessageControlKHR.

Kyle Brenneman kbrenneman at nvidia.com
Thu Sep 8 18:17:50 UTC 2016


Check if the attribute list is valid even if the callback is NULL.

Set the callback pointer whether or not the attribute list is NULL.
---
 src/egl/main/eglapi.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 3bbf3de..6f30ed6 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2042,36 +2042,37 @@ eglLabelObjectKHR(
 static EGLint
 eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback, const EGLAttrib *attrib_list)
 {
+   unsigned int newEnabled;
+
    _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_BAD_ALLOC);
 
    mtx_lock(_eglGlobal.Mutex);
 
-   if (callback != NULL) {
-      if (attrib_list != NULL) {
-         unsigned int newEnabled = _eglGlobal.debugTypesEnabled;
-         int i;
-
-         for (i = 0; attrib_list[i] != EGL_NONE; i += 2) {
-            if (attrib_list[i] >= EGL_DEBUG_MSG_CRITICAL_KHR &&
-                  attrib_list[i] <= EGL_DEBUG_MSG_INFO_KHR) {
-               if (attrib_list[i + 1]) {
-                  newEnabled |= DebugBitFromType(attrib_list[i]);
-               } else {
-                  newEnabled &= ~DebugBitFromType(attrib_list[i]);
-               }
+   newEnabled = _eglGlobal.debugTypesEnabled;
+   if (attrib_list != NULL) {
+      int i;
+      for (i = 0; attrib_list[i] != EGL_NONE; i += 2) {
+         if (attrib_list[i] >= EGL_DEBUG_MSG_CRITICAL_KHR &&
+               attrib_list[i] <= EGL_DEBUG_MSG_INFO_KHR) {
+            if (attrib_list[i + 1]) {
+               newEnabled |= DebugBitFromType(attrib_list[i]);
             } else {
-               // On error, set the last error code, call the current
-               // debug callback, and return the error code.
-               mtx_unlock(_eglGlobal.Mutex);
-               _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
-                     "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
-               return EGL_BAD_ATTRIBUTE;
+               newEnabled &= ~DebugBitFromType(attrib_list[i]);
             }
+         } else {
+            // On error, set the last error code, call the current
+            // debug callback, and return the error code.
+            mtx_unlock(_eglGlobal.Mutex);
+            _eglReportError(EGL_BAD_ATTRIBUTE, NULL,
+                  "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]);
+            return EGL_BAD_ATTRIBUTE;
          }
-
-         _eglGlobal.debugCallback = callback;
-         _eglGlobal.debugTypesEnabled = newEnabled;
       }
+   }
+
+   if (callback != NULL) {
+      _eglGlobal.debugCallback = callback;
+      _eglGlobal.debugTypesEnabled = newEnabled;
    } else {
       _eglGlobal.debugCallback = NULL;
       _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR;
-- 
2.7.4



More information about the mesa-dev mailing list