Fix eglQueryString() to support long EGL_EXTENSIONS string. 48/30148/1
authorTakanari Hayama <taki@igel.co.jp>
Fri, 28 Mar 2014 04:41:57 +0000 (13:41 +0900)
committerTony SIM <chinyeow.sim.xt@renesas.com>
Wed, 12 Nov 2014 05:40:27 +0000 (13:40 +0800)
eglQueryString() had fixed size string buffer as a place holder
for EGL_EXTENSIONS to avoid dynamic memory allocation. However,
this caused an issue when the backend eglQueryString() returned
the longer string that is more than this fixed size string buffer.

We now allocate the string buffer dynamically.

Change-Id: I107b5511bf1a31af6e83b9320f0b44c279d50b52
Signed-off-by: Tony SIM <chinyeow.sim.xt@renesas.com>
egl.c

diff --git a/egl.c b/egl.c
index d9438d4..6957019 100644 (file)
--- a/egl.c
+++ b/egl.c
@@ -212,9 +212,11 @@ EGLBoolean eglTerminate(EGLDisplay dpy)
        return _eglTerminate(dpy);
 }
 
+#define EGL_WL_EXT_STRING "EGL_WL_bind_wayland_display "
+
 const char *eglQueryString(EGLDisplay dpy, EGLint name)
 {
-       static char _eglextstr[512];
+       static char *_eglextstr = NULL;
        const char *ret;
 
        EGL_DEBUG("%s: %s\n", __FILE__, __func__);
@@ -224,10 +226,18 @@ const char *eglQueryString(EGLDisplay dpy, EGLint name)
 #ifdef WANT_WAYLAND
        if (name == EGL_EXTENSIONS) {
                assert(ret != NULL);
-               snprintf(_eglextstr, sizeof(_eglextstr),
-                        "%sEGL_WL_bind_wayland_display ", ret);
+
+               if (!_eglextstr) {
+                       _eglextstr = calloc(1, strlen(ret) + strlen(EGL_WL_EXT_STRING) + 1);
+                       if (_eglextstr) {
+                               strcat(_eglextstr, ret);
+                               strcat(_eglextstr, EGL_WL_EXT_STRING);
+                       } else {
+                               _eglextstr = (char*)ret;
+                       }
+               }
+
                ret = _eglextstr;
-               return ret;
        }
 #endif
        return ret;