]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
getpath.c: fix test to detech PyUnicode_AsWideChar() failure
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 10 Nov 2010 14:12:20 +0000 (14:12 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 10 Nov 2010 14:12:20 +0000 (14:12 +0000)
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.

Modules/getpath.c

index c9353c72371c3a605b8e2372b17d431bf019a9ee..16b3b2a008f7b911c82139b8a5376678423ec64e 100644 (file)
@@ -355,17 +355,17 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_exec_prefix
             char buf[MAXPATHLEN+1];
             PyObject *decoded;
             wchar_t rel_builddir_path[MAXPATHLEN+1];
-            size_t n;
             n = fread(buf, 1, MAXPATHLEN, f);
             buf[n] = '\0';
             fclose(f);
             decoded = PyUnicode_DecodeUTF8(buf, n, "surrogateescape");
             if (decoded != NULL) {
-                n = PyUnicode_AsWideChar((PyUnicodeObject*)decoded,
+                Py_ssize_t k;
+                k = PyUnicode_AsWideChar((PyUnicodeObject*)decoded,
                                          rel_builddir_path, MAXPATHLEN);
                 Py_DECREF(decoded);
-                if (n >= 0) {
-                    rel_builddir_path[n] = L'\0';
+                if (k >= 0) {
+                    rel_builddir_path[k] = L'\0';
                     wcscpy(exec_prefix, argv0_path);
                     joinpath(exec_prefix, rel_builddir_path);
                     return -1;