diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2008-09-03 18:58:51 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2008-09-03 18:58:51 (GMT) |
commit | fff953048f965b4f0a56f775d3f4ce1634df3da7 (patch) | |
tree | 528a28abc4354994c6818caac6257c52bc0d1704 /Modules | |
parent | 658fad8aae60e6c25a102fb56884bf66577366f8 (diff) | |
download | cpython-fff953048f965b4f0a56f775d3f4ce1634df3da7.zip cpython-fff953048f965b4f0a56f775d3f4ce1634df3da7.tar.gz cpython-fff953048f965b4f0a56f775d3f4ce1634df3da7.tar.bz2 |
Issue #3696: Error parsing arguments on OpenBSD <= 4.4 and Cygwin.
Patch by Amaury Forgeot d'Arc, reviewed by me.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_localemodule.c | 8 | ||||
-rw-r--r-- | Modules/python.c | 15 |
2 files changed, 22 insertions, 1 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 8441f1e..fb2837e 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -49,7 +49,11 @@ static PyObject *Error; static PyObject* str2uni(const char* s) { +#ifdef HAVE_BROKEN_MBSTOWCS + size_t needed = strlen(s); +#else size_t needed = mbstowcs(NULL, s, 0); +#endif size_t res1; wchar_t smallbuf[30]; wchar_t *dest; @@ -67,7 +71,11 @@ str2uni(const char* s) } /* This shouldn't fail now */ res1 = mbstowcs(dest, s, needed+1); +#ifdef HAVE_BROKEN_MBSTOWCS + assert(res1 != (size_t)-1); +#else assert(res1 == needed); +#endif res2 = PyUnicode_FromWideChar(dest, res1); if (dest != smallbuf) PyMem_Free(dest); diff --git a/Modules/python.c b/Modules/python.c index c1de64a..1ff2298 100644 --- a/Modules/python.c +++ b/Modules/python.c @@ -40,7 +40,16 @@ main(int argc, char **argv) oldloc = setlocale(LC_ALL, NULL); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { +#ifdef HAVE_BROKEN_MBSTOWCS + /* Some platforms have a broken implementation of + * mbstowcs which does not count the characters that + * would result from conversion. Use an upper bound. + */ + size_t argsize = strlen(argv[i]); +#else size_t argsize = mbstowcs(NULL, argv[i], 0); +#endif + size_t count; if (argsize == (size_t)-1) { fprintf(stderr, "Could not convert argument %d to string", i); return 1; @@ -51,7 +60,11 @@ main(int argc, char **argv) fprintf(stderr, "out of memory"); return 1; } - mbstowcs(argv_copy[i], argv[i], argsize+1); + count = mbstowcs(argv_copy[i], argv[i], argsize+1); + if (count == (size_t)-1) { + fprintf(stderr, "Could not convert argument %d to string", i); + return 1; + } } setlocale(LC_ALL, oldloc); res = Py_Main(argc, argv_copy); |