Skip to content

Commit

Permalink
ui/sdl2: Check return value from g_setenv()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
pm215 authored and kraxel committed Aug 10, 2021
1 parent da77adb commit 6ff5b5d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ui/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 6ff5b5d

Please sign in to comment.