Rex Dieter 5187332
From d4efd5ab810e92202efe672be29136324dd2a3f9 Mon Sep 17 00:00:00 2001
Rex Dieter 5187332
From: =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= <davispuh@gmail.com>
Rex Dieter 5187332
Date: Mon, 28 Dec 2015 05:43:18 +0200
Rex Dieter 5187332
Subject: [PATCH] Check for NULL from glGetString
Rex Dieter 5187332
Rex Dieter 5187332
glGetString can return NULL pointer in case of error
Rex Dieter 5187332
so check for it before using.
Rex Dieter 5187332
Rex Dieter 5187332
Change-Id: Ia07424c8f2b3ce6dce675514900a509e3ef3b739
Rex Dieter 5187332
---
Rex Dieter 5187332
 src/particles/qquickimageparticle.cpp              |  6 ++++--
Rex Dieter 5187332
 src/quick/scenegraph/qsgcontext.cpp                | 22 ++++++++++++++++------
Rex Dieter 5187332
 .../qsgdefaultdistancefieldglyphcache.cpp          |  8 +++++---
Rex Dieter 5187332
 src/quick/scenegraph/util/qsgatlastexture.cpp      |  4 ++--
Rex Dieter 5187332
 4 files changed, 27 insertions(+), 13 deletions(-)
Rex Dieter 5187332
Rex Dieter 5187332
diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp
Rex Dieter 5187332
index d78a350..b54861e 100644
Rex Dieter 5187332
--- a/src/particles/qquickimageparticle.cpp
Rex Dieter 5187332
+++ b/src/particles/qquickimageparticle.cpp
Rex Dieter 5187332
@@ -1276,14 +1276,16 @@ void QQuickImageParticle::finishBuildParticleNodes(QSGNode** node)
Rex Dieter 5187332
     // OS X 10.8.3 introduced a bug in the AMD drivers, for at least the 2011 macbook pros,
Rex Dieter 5187332
     // causing point sprites who read gl_PointCoord in the frag shader to come out as
Rex Dieter 5187332
     // green-red blobs.
Rex Dieter 5187332
-    if (perfLevel < Deformable && strstr((char *) glGetString(GL_VENDOR), "ATI")) {
Rex Dieter 5187332
+    const char *vendor = (const char *) glGetString(GL_VENDOR);
Rex Dieter 5187332
+    if (perfLevel < Deformable && vendor && strstr(vendor, "ATI")) {
Rex Dieter 5187332
         perfLevel = Deformable;
Rex Dieter 5187332
     }
Rex Dieter 5187332
 #endif
Rex Dieter 5187332
 
Rex Dieter 5187332
 #ifdef Q_OS_LINUX
Rex Dieter 5187332
     // Nouveau drivers can potentially freeze a machine entirely when taking the point-sprite path.
Rex Dieter 5187332
-    if (perfLevel < Deformable && strstr((const char *) glGetString(GL_VENDOR), "nouveau"))
Rex Dieter 5187332
+    const char *vendor = (const char *) glGetString(GL_VENDOR);
Rex Dieter 5187332
+    if (perfLevel < Deformable && vendor && strstr(vendor, "nouveau"))
Rex Dieter 5187332
         perfLevel = Deformable;
Rex Dieter 5187332
 #endif
Rex Dieter 5187332
 
Rex Dieter 5187332
diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp
Rex Dieter 5187332
index dd6977e..43d549f 100644
Rex Dieter 5187332
--- a/src/quick/scenegraph/qsgcontext.cpp
Rex Dieter 5187332
+++ b/src/quick/scenegraph/qsgcontext.cpp
Rex Dieter 5187332
@@ -624,14 +624,24 @@ void QSGRenderContext::initialize(QOpenGLContext *context)
Rex Dieter 5187332
     m_sg->renderContextInitialized(this);
Rex Dieter 5187332
 
Rex Dieter 5187332
 #ifdef Q_OS_LINUX
Rex Dieter 5187332
+    while (funcs->glGetError() != GL_NO_ERROR);
Rex Dieter 5187332
+
Rex Dieter 5187332
     const char *vendor = (const char *) funcs->glGetString(GL_VENDOR);
Rex Dieter 5187332
-    if (strstr(vendor, "nouveau"))
Rex Dieter 5187332
-        m_brokenIBOs = true;
Rex Dieter 5187332
     const char *renderer = (const char *) funcs->glGetString(GL_RENDERER);
Rex Dieter 5187332
-    if (strstr(renderer, "llvmpipe"))
Rex Dieter 5187332
-        m_serializedRender = true;
Rex Dieter 5187332
-    if (strstr(vendor, "Hisilicon Technologies") && strstr(renderer, "Immersion.16"))
Rex Dieter 5187332
-        m_brokenIBOs = true;
Rex Dieter 5187332
+
Rex Dieter 5187332
+    if (vendor && renderer) {
Rex Dieter 5187332
+        if (strstr(vendor, "nouveau"))
Rex Dieter 5187332
+            m_brokenIBOs = true;
Rex Dieter 5187332
+        if (strstr(renderer, "llvmpipe"))
Rex Dieter 5187332
+            m_serializedRender = true;
Rex Dieter 5187332
+        if (strstr(vendor, "Hisilicon Technologies") && strstr(renderer, "Immersion.16"))
Rex Dieter 5187332
+            m_brokenIBOs = true;
Rex Dieter 5187332
+    } else {
Rex Dieter 5187332
+        GLenum err;
Rex Dieter 5187332
+        while ((err = funcs->glGetError()) != GL_NO_ERROR) {
Rex Dieter 5187332
+            qWarning("QSGRenderContext::initialize: GL error %x from glGetString", err);
Rex Dieter 5187332
+        }
Rex Dieter 5187332
+    }
Rex Dieter 5187332
 #endif
Rex Dieter 5187332
 
Rex Dieter 5187332
     emit initialized();
Rex Dieter 5187332
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
Rex Dieter 5187332
index dcc485c..43e234b 100644
Rex Dieter 5187332
--- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
Rex Dieter 5187332
+++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
Rex Dieter 5187332
@@ -488,9 +488,11 @@ bool QSGDefaultDistanceFieldGlyphCache::useTextureUploadWorkaround() const
Rex Dieter 5187332
     static bool set = false;
Rex Dieter 5187332
     static bool useWorkaround = false;
Rex Dieter 5187332
     if (!set) {
Rex Dieter 5187332
-        useWorkaround = qstrcmp(reinterpret_cast<const char*>(m_funcs->glGetString(GL_RENDERER)),
Rex Dieter 5187332
-                                "Mali-400 MP") == 0;
Rex Dieter 5187332
-        set = true;
Rex Dieter 5187332
+        const char *renderer = reinterpret_cast<const char*>(m_funcs->glGetString(GL_RENDERER));
Rex Dieter 5187332
+        if (renderer) {
Rex Dieter 5187332
+            useWorkaround = qstrcmp(renderer, "Mali-400 MP") == 0;
Rex Dieter 5187332
+            set = true;
Rex Dieter 5187332
+        }
Rex Dieter 5187332
     }
Rex Dieter 5187332
     return useWorkaround;
Rex Dieter 5187332
 }
Rex Dieter 5187332
diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp
Rex Dieter 5187332
index 8e8e870..d726907 100644
Rex Dieter 5187332
--- a/src/quick/scenegraph/util/qsgatlastexture.cpp
Rex Dieter 5187332
+++ b/src/quick/scenegraph/util/qsgatlastexture.cpp
Rex Dieter 5187332
@@ -150,13 +150,13 @@ Atlas::Atlas(const QSize &size)
Rex Dieter 5187332
         wrongfullyReportsBgra8888Support = false;
Rex Dieter 5187332
 
Rex Dieter 5187332
     const char *ext = (const char *) QOpenGLContext::currentContext()->functions()->glGetString(GL_EXTENSIONS);
Rex Dieter 5187332
-    if (!wrongfullyReportsBgra8888Support
Rex Dieter 5187332
+    if (!wrongfullyReportsBgra8888Support && ext
Rex Dieter 5187332
             && (strstr(ext, "GL_EXT_bgra")
Rex Dieter 5187332
                 || strstr(ext, "GL_EXT_texture_format_BGRA8888")
Rex Dieter 5187332
                 || strstr(ext, "GL_IMG_texture_format_BGRA8888"))) {
Rex Dieter 5187332
         m_internalFormat = m_externalFormat = GL_BGRA;
Rex Dieter 5187332
 #ifdef Q_OS_IOS
Rex Dieter 5187332
-    } else if (strstr(ext, "GL_APPLE_texture_format_BGRA8888")) {
Rex Dieter 5187332
+    } else if (ext && strstr(ext, "GL_APPLE_texture_format_BGRA8888")) {
Rex Dieter 5187332
         m_internalFormat = GL_RGBA;
Rex Dieter 5187332
         m_externalFormat = GL_BGRA;
Rex Dieter 5187332
 #endif // IOS
Rex Dieter 5187332
-- 
Rex Dieter 5187332
1.9.3
Rex Dieter 5187332