[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] ui/sdl2: Check return value from g_setenv()
From: |
Peter Maydell |
Subject: |
[PATCH] ui/sdl2: Check return value from g_setenv() |
Date: |
Mon, 9 Aug 2021 17:14:24 +0100 |
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>
---
I followed existing practice in this function for how it
deals with errors (ie, fprintf to stderr and exit).
---
ui/sdl2.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 36d9010cb6c..17c0ec30ebf 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)) {
--
2.20.1
- [PATCH] ui/sdl2: Check return value from g_setenv(),
Peter Maydell <=