tests/ecore_wl2: Fix unchecked return value
authorChristopher Michael <devilhorns@comcast.net>
Wed, 10 Jun 2020 12:32:40 +0000 (08:32 -0400)
committerJongmin Lee <jm105.lee@samsung.com>
Wed, 10 Jun 2020 21:27:14 +0000 (06:27 +0900)
Coverity reports eglChooseConfig is called without checking return
value here. This patch fixes the issue by checking the return value
and by also making _init_egl return a bool so that we can fail the
test if eglChooseConfig results in failure.

Fixes Coverity CID1412365

src/tests/ecore_wl2/ecore_wl2_test_window.c
src/tests/ecore_wl2/ecore_wl2_tests_helper_egl.h

index c094515e930ce84c71b83f5d0dc3701d6f2bfa6a..4b9e734d612cb891f7963fc06afe535d293296aa 100644 (file)
@@ -324,6 +324,7 @@ _test_activated_window_activate(void *data EINA_UNUSED, int type EINA_UNUSED, vo
 EFL_START_TEST(wl2_window_activated)
 {
    Test_Data *td;
+   Eina_Bool ret = EINA_FALSE;
 
    ecore_wl2_init();
 
@@ -345,7 +346,9 @@ EFL_START_TEST(wl2_window_activated)
 
    ecore_wl2_window_show(td->win);
 
-   _init_egl(td);
+   ret = _init_egl(td);
+   fail_if(ret != EINA_TRUE);
+
    td->handler = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE_COMPLETE,
                                          _test_activated_configure_complete, td);
    ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ACTIVATE,
index 27fa4a615e9663aa8e6a3a1a1fec5ac548392b41..f235a481bb786b3fdd9abfe767bdd53736cec96a 100644 (file)
@@ -5,7 +5,7 @@
 #include <EGL/egl.h>
 #include <GLES2/gl2.h>
 
-static void
+static Eina_Bool
 _init_egl(Test_Data *td)
 {
    eglBindAPI(EGL_OPENGL_API);
@@ -21,18 +21,30 @@ _init_egl(Test_Data *td)
 
    td->egl_display =
      eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get(td->display));
+
    eglInitialize(td->egl_display, NULL, NULL);
-   eglChooseConfig(td->egl_display, attributes, &td->egl_conf, 1, &num_config);
+
+   if (!eglChooseConfig(td->egl_display, attributes, &td->egl_conf,
+                        1, &num_config))
+     {
+        ERR("Failed to choose egl config");
+        eglTerminate(td->egl_display);
+        return EINA_FALSE;
+     }
+
    td->egl_context =
      eglCreateContext(td->egl_display, td->egl_conf, EGL_NO_CONTEXT, NULL);
 
    td->egl_window = wl_egl_window_create(td->surface, td->width, td->height);
+
    td->egl_surface =
      eglCreateWindowSurface(td->egl_display,
                             td->egl_conf, td->egl_window, NULL);
 
    eglMakeCurrent(td->egl_display, td->egl_surface,
                   td->egl_surface, td->egl_context);
+
+   return EINA_TRUE;
 }
 
 static void