Coverity CIDs 468127 468134 468148

These Coverity warnings all relate to the user of g_setenv() where the
return result isn't checked.

An additional void function g_setenv_log() is provided which logs
failures to set environment variables, and returns no status. This is
used in all the places where g_setenv_is currently called.
This commit is contained in:
matt335672
2025-04-17 14:36:25 +01:00
parent f2dd3fb3dc
commit 417076b215
7 changed files with 55 additions and 31 deletions
+17
View File
@@ -3589,6 +3589,23 @@ g_setenv(const char *name, const char *value, int rewrite)
#endif
}
/*****************************************************************************/
/* does not work in win32 */
void
g_setenv_log(const char *name, const char *value, int rewrite)
{
#if defined(_WIN32)
return 0;
#else
if (setenv(name, value, rewrite) != 0)
{
LOG(LOG_LEVEL_WARNING, "Unable to set environment variable '%s' [%s]",
name, g_get_strerror());
}
#endif
}
/*****************************************************************************/
/* does not work in win32 */
char *
+11
View File
@@ -381,6 +381,17 @@ int g_setpgid(int pid, int pgid);
void g_clearenv(void);
int g_setenv(const char *name, const char *value, int rewrite);
char *g_getenv(const char *name);
/**
* Calls g_setenv(), logging failures
*
* @param name Name to set
* @param value String to set $name to
* @param rewrite Set to non-zero to allow rewriting of existing names
*
* Unlike g_setenv() this function returns no value. Use this function if the
* only reasonable thing to do on failure is to log it.
*/
void g_setenv_log(const char *name, const char *value, int rewrite);
int g_exit(int exit_code);
int g_getpid(void);
int g_sigterm(int pid);