mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Mark Hammond should get his act into gear (his words :-). Zero length
strings _are_ valid!
This commit is contained in:
parent
301f3f6baa
commit
03e29f1ae9
1 changed files with 7 additions and 2 deletions
|
@ -1554,7 +1554,7 @@ PyObject *PyUnicode_DecodeMBCS(const char *s,
|
||||||
|
|
||||||
/* First get the size of the result */
|
/* First get the size of the result */
|
||||||
DWORD usize = MultiByteToWideChar(CP_ACP, 0, s, size, NULL, 0);
|
DWORD usize = MultiByteToWideChar(CP_ACP, 0, s, size, NULL, 0);
|
||||||
if (usize==0)
|
if (size > 0 && usize==0)
|
||||||
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
|
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
|
||||||
|
|
||||||
v = _PyUnicode_New(usize);
|
v = _PyUnicode_New(usize);
|
||||||
|
@ -1577,9 +1577,14 @@ PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p,
|
||||||
{
|
{
|
||||||
PyObject *repr;
|
PyObject *repr;
|
||||||
char *s;
|
char *s;
|
||||||
|
DWORD mbcssize;
|
||||||
|
|
||||||
|
/* If there are no characters, bail now! */
|
||||||
|
if (size==0)
|
||||||
|
return PyString_FromString("");
|
||||||
|
|
||||||
/* First get the size of the result */
|
/* First get the size of the result */
|
||||||
DWORD mbcssize = WideCharToMultiByte(CP_ACP, 0, p, size, NULL, 0, NULL, NULL);
|
mbcssize = WideCharToMultiByte(CP_ACP, 0, p, size, NULL, 0, NULL, NULL);
|
||||||
if (mbcssize==0)
|
if (mbcssize==0)
|
||||||
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
|
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue