gtestutils: Check for failure to setenv() and return

This is very unlikely to happen, but it makes Coverity happier.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1474388
This commit is contained in:
Philip Withnall 2022-12-14 15:11:10 +00:00
parent a0dbaeed2f
commit b012c3470b

View File

@ -1684,7 +1684,12 @@ void
g_free (tmpl); g_free (tmpl);
/* Propagate the temporary directory to subprocesses. */ /* Propagate the temporary directory to subprocesses. */
g_setenv ("G_TEST_TMPDIR", test_isolate_dirs_tmpdir, TRUE); if (!g_setenv ("G_TEST_TMPDIR", test_isolate_dirs_tmpdir, TRUE))
{
g_printerr ("%s: Failed to set environment variable %s\n",
(*argv)[0], "G_TEST_TMPDIR");
exit (1);
}
/* And clear the traditional environment variables so subprocesses /* And clear the traditional environment variables so subprocesses
* spawned by the code under test cant trash anything. If a test * spawned by the code under test cant trash anything. If a test
@ -1710,7 +1715,14 @@ void
gsize i; gsize i;
for (i = 0; i < G_N_ELEMENTS (overridden_environment_variables); i++) for (i = 0; i < G_N_ELEMENTS (overridden_environment_variables); i++)
g_setenv (overridden_environment_variables[i], "/dev/null", TRUE); {
if (!g_setenv (overridden_environment_variables[i], "/dev/null", TRUE))
{
g_printerr ("%s: Failed to set environment variable %s\n",
(*argv)[0], overridden_environment_variables[i]);
exit (1);
}
}
} }
} }