summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2012-06-21 14:33:09 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2012-06-21 14:33:09 (GMT)
commitf36d65c7c87234814867661f5089e903ae7319e7 (patch)
tree2dc7b26ee83c93e4faf6c9755779a7147af12630 /PC
parent56bf6f82021a842d3619e76a9c9d67f54b56fe6f (diff)
downloadcpython-f36d65c7c87234814867661f5089e903ae7319e7.zip
cpython-f36d65c7c87234814867661f5089e903ae7319e7.tar.gz
cpython-f36d65c7c87234814867661f5089e903ae7319e7.tar.bz2
Use GetEnvironmentVariableW instead of _wgetenv to silence VC warnings.
Diffstat (limited to 'PC')
-rw-r--r--PC/launcher.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/PC/launcher.c b/PC/launcher.c
index 22d2974..5792d1b 100644
--- a/PC/launcher.c
+++ b/PC/launcher.c
@@ -54,22 +54,31 @@ skip_whitespace(wchar_t * p)
}
/*
- * This function is here to minimise Visual Studio
- * warnings about security implications of getenv, and to
- * treat blank values as if they are absent.
+ * This function is here to simplify memory management
+ * and to treat blank values as if they are absent.
*/
static wchar_t * get_env(wchar_t * key)
{
- wchar_t * result = _wgetenv(key);
-
- if (result) {
- result = skip_whitespace(result);
- if (*result == L'\0')
- result = NULL;
+ /* This is not thread-safe, just like getenv */
+ static wchar_t buf[256];
+ DWORD result = GetEnvironmentVariableW(key, buf, 256);
+
+ if (result > 256) {
+ /* Large environment variable. Accept some leakage */
+ wchar_t *buf2 = (wchar_t*)malloc(sizeof(wchar_t) * (result+1));
+ GetEnvironmentVariableW(key, buf2, result);
+ return buf2;
}
- return result;
+
+ if (result == 0)
+ /* Either some error, e.g. ERROR_ENVVAR_NOT_FOUND,
+ or an empty environment variable. */
+ return NULL;
+
+ return buf;
}
+
static void
debug(wchar_t * format, ...)
{