ui/sdl2: Check return value from g_setenv()
PATCH 1/1 ui/sdl2: Check return value from g_setenv()
Setting environment variables can fail; check the return value from g_setenv() and bail out if we couldn't set SDL_VIDEODRIVER.
---
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(-)
ui/sdl2.c +4 -1
@@ -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 )) {
Signature · 1 line
2.20.1
Hi,
Quoted 2 lines
Setting environment variables can fail; check the return value from
g_setenv()and bail out if we couldn't setSDL_VIDEODRIVER.
Hmm, looking at the comment I'm wondering whenever we maybe should just drop the setenv (after 6.1). It's quite old, I doubt svgalib talking directly to the hardware is still a thing these days, and we have the x11 -> wayland shift happening ...
take care,
Gerd
Quoted 9 lines · Peter Maydell
Setting environment variables can fail; check the return value from
g_setenv()and bail out if we couldn't setSDL_VIDEODRIVER.Fixes Coverity 1458798Signed-off-by Peter Maydell <[email protected]>---
I followed existing practice in this function for how it deals with errors (ie, fprintf to stderr and exit).
---
Queued for 6.1 (given that the "drop setenv altogether" idea clearly is 6.2 material).
thanks,
Gerd