Kaydet (Commit) 47f637ce authored tarafından Victor Stinner's avatar Victor Stinner

getpath.c: fix test to detech PyUnicode_AsWideChar() failure

PyUnicode_AsWideChar() result is signed, whereas it was stored in a unsigned
variable, and then the test was "n >= 0" which is always true to an unsigned
number. Patch written by Hallvard B Furuseth.
üst cf9f9803
...@@ -355,17 +355,17 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_exec_prefix ...@@ -355,17 +355,17 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_exec_prefix
char buf[MAXPATHLEN+1]; char buf[MAXPATHLEN+1];
PyObject *decoded; PyObject *decoded;
wchar_t rel_builddir_path[MAXPATHLEN+1]; wchar_t rel_builddir_path[MAXPATHLEN+1];
size_t n;
n = fread(buf, 1, MAXPATHLEN, f); n = fread(buf, 1, MAXPATHLEN, f);
buf[n] = '\0'; buf[n] = '\0';
fclose(f); fclose(f);
decoded = PyUnicode_DecodeUTF8(buf, n, "surrogateescape"); decoded = PyUnicode_DecodeUTF8(buf, n, "surrogateescape");
if (decoded != NULL) { if (decoded != NULL) {
n = PyUnicode_AsWideChar((PyUnicodeObject*)decoded, Py_ssize_t k;
k = PyUnicode_AsWideChar((PyUnicodeObject*)decoded,
rel_builddir_path, MAXPATHLEN); rel_builddir_path, MAXPATHLEN);
Py_DECREF(decoded); Py_DECREF(decoded);
if (n >= 0) { if (k >= 0) {
rel_builddir_path[n] = L'\0'; rel_builddir_path[k] = L'\0';
wcscpy(exec_prefix, argv0_path); wcscpy(exec_prefix, argv0_path);
joinpath(exec_prefix, rel_builddir_path); joinpath(exec_prefix, rel_builddir_path);
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment