Protect mysetenv() fron any NULL string pointers
...such as those we seem to be receiving from _nl_locale_name() on 64-bit Windows under newer MinGW/MSYS (see big thread on tuxpaint-devel with reports from Shin-ichi).
This commit is contained in:
parent
9c010ffd40
commit
1bee12246e
1 changed files with 20 additions and 8 deletions
28
src/i18n.c
28
src/i18n.c
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
$Id$
|
||||
|
||||
June 14, 2002 - July 26, 2020
|
||||
June 14, 2002 - October 25, 2021
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
@ -966,14 +966,26 @@ static void set_langint_from_locale_string(const char *restrict loc)
|
|||
static void mysetenv(const char *name, const char *value)
|
||||
{
|
||||
#ifdef HAVE_SETENV
|
||||
setenv(name, value, 1);
|
||||
#else
|
||||
int len = strlen(name) + 1 + strlen(value) + 1;
|
||||
char *str = malloc(len);
|
||||
|
||||
sprintf(str, "%s=%s", name, value);
|
||||
putenv(str);
|
||||
int len;
|
||||
char *str;
|
||||
#endif
|
||||
|
||||
if (name != NULL && value != NULL) {
|
||||
#ifdef HAVE_SETENV
|
||||
setenv(name, value, 1);
|
||||
#else
|
||||
len = strlen(name) + 1 + strlen(value) + 1;
|
||||
str = malloc(len);
|
||||
|
||||
sprintf(str, "%s=%s", name, value);
|
||||
putenv(str);
|
||||
#endif
|
||||
} else {
|
||||
fprintf(stderr, "WARNING: mysetenv() received a null pointer. name=%s, value=%s\n",
|
||||
(name == NULL ? "NULL" : name),
|
||||
(value == NULL ? "NULL" : value)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue