dupenv apparently returns the size fo the buffer not the string

This commit is contained in:
Kovid Goyal 2018-02-14 07:13:34 +05:30
parent ac181d2198
commit 8f82de9406
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -237,8 +237,8 @@ winutil_getenv(PyObject *self, PyObject *args) {
wchar_t *buf = NULL; wchar_t *buf = NULL;
size_t sz = 0; size_t sz = 0;
PyObject *ans = NULL; PyObject *ans = NULL;
if (_wdupenv_s(&buf, &sz, q) != 0 || buf == NULL) { ans = Py_None; Py_INCREF(ans); } if (_wdupenv_s(&buf, &sz, q) != 0 || buf == NULL || sz == 0) { ans = Py_None; Py_INCREF(ans); }
else ans = PyUnicode_FromWideChar(buf, sz); else ans = PyUnicode_FromWideChar(buf, sz - 1);
if (buf) free(buf); if (buf) free(buf);
return ans; return ans;
} }