summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-05-03 11:03:24 (GMT)
committerGuido van Rossum <guido@python.org>2000-05-03 11:03:24 (GMT)
commita6edfd9737043420cfbf248ccae39ed344bc06a1 (patch)
tree6222dadf315b6ac6905ccc9edbdc2599d9f49ebe
parent69652f8abed6e02f1a824ff9c201e75681bd70fa (diff)
downloadcpython-a6edfd9737043420cfbf248ccae39ed344bc06a1.zip
cpython-a6edfd9737043420cfbf248ccae39ed344bc06a1.tar.gz
cpython-a6edfd9737043420cfbf248ccae39ed344bc06a1.tar.bz2
Mark Hammond:
Fixes the MBCS codec to work correctly with zero length strings.
-rw-r--r--Objects/unicodeobject.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 7a68dd4..e843d1a 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1555,7 +1555,7 @@ PyObject *PyUnicode_DecodeMBCS(const char *s,
/* First get the size of the result */
DWORD usize = MultiByteToWideChar(CP_ACP, 0, s, size, NULL, 0);
- if (usize==0)
+ if (size > 0 && usize==0)
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
v = _PyUnicode_New(usize);
@@ -1578,9 +1578,14 @@ PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p,
{
PyObject *repr;
char *s;
+ DWORD mbcssize;
+
+ /* If there are no characters, bail now! */
+ if (size==0)
+ return PyString_FromString("");
/* 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)
return PyErr_SetFromWindowsErrWithFilename(0, NULL);