diff mbox series

[PULL,3/3] ui/sdl2: Check return value from g_setenv()

Message ID 20210810121840.2525726-4-kraxel@redhat.com
State Accepted
Commit 6ff5b5d6d521001135d1bd5c609e8834099f01d8
Headers show
Series None | expand

Commit Message

Gerd Hoffmann Aug. 10, 2021, 12:18 p.m. UTC
From: Peter Maydell <peter.maydell@linaro.org>


Setting environment variables can fail; check the return value
from g_setenv() and bail out if we couldn't set SDL_VIDEODRIVER.

Fixes: Coverity 1458798
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Message-Id: <20210809161424.32355-1-peter.maydell@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

---
 ui/sdl2.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

-- 
2.31.1
diff mbox series

Patch

diff --git a/ui/sdl2.c b/ui/sdl2.c
index 36d9010cb6c1..17c0ec30ebff 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -817,7 +817,10 @@  static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
      * This is a bit hackish but saves us from bigger problem.
      * Maybe it's a good idea to fix this in SDL instead.
      */
-    g_setenv("SDL_VIDEODRIVER", "x11", 0);
+    if (!g_setenv("SDL_VIDEODRIVER", "x11", 0)) {
+        fprintf(stderr, "Could not set SDL_VIDEODRIVER environment variable\n");
+        exit(1);
+    }
 #endif
 
     if (SDL_Init(SDL_INIT_VIDEO)) {