From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [PATCH] ui/sdl2: Check return value from g_setenv()
Date: Mon, 9 Aug 2021 17:14:24 +0100 [thread overview]
Message-ID: <20210809161424.32355-1-peter.maydell@linaro.org> (raw)
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
next reply other threads:[~2021-08-09 16:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 16:14 Peter Maydell [this message]
2021-08-10 5:50 ` [PATCH] ui/sdl2: Check return value from g_setenv() Gerd Hoffmann
2021-08-10 8:57 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210809161424.32355-1-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).