]> granicus.if.org Git - python/commitdiff
Mark Hammond:
authorGuido van Rossum <guido@python.org>
Wed, 3 May 2000 11:03:24 +0000 (11:03 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 3 May 2000 11:03:24 +0000 (11:03 +0000)
Fixes the MBCS codec to work correctly with zero length strings.

Objects/unicodeobject.c

index 7a68dd40104d51b31583b5f30004ec3d9afa33ba..e843d1a6b035b1e8da13863e8328b845d4c88307 100644 (file)
@@ -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);