[Patches] MBCS codes fails on zero length string.

Mark Hammond mhammond@skippinet.com.au
Wed, 3 May 2000 16:55:34 +1000


Fixes the MBCS codec to work correctly with zero length strings.

Release info:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under copyright,
patent or other rights or interests ("claims").  To the extent that
I have any such claims, I hereby grant to CNRI a nonexclusive,
irrevocable, royalty-free, worldwide license to reproduce,
distribute, perform and/or display publicly, prepare derivative
versions, and otherwise use this contribution as part of the Python
software and its related documentation, or any derivative versions
thereof, at no cost to CNRI or its licensed users, and to authorize
others to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether
or not to incorporate this contribution in the Python software and
its related documentation.  I further grant CNRI permission to use
my name and other identifying information provided to CNRI by me for
use in connection with the Python software and its related
documentation.

Mark.

diff -c -r2.13 unicodeobject.c
*** unicodeobject.c	2000/05/01 21:27:20	2.13
--- unicodeobject.c	2000/05/03 06:53:20
***************
*** 1555,1561 ****

      /* First get the size of the result */
      DWORD usize = MultiByteToWideChar(CP_ACP, 0, s, size, NULL,
0);
!     if (usize==0)
          return PyErr_SetFromWindowsErrWithFilename(0, NULL);

      v = _PyUnicode_New(usize);
--- 1555,1561 ----

      /* First get the size of the result */
      DWORD usize = MultiByteToWideChar(CP_ACP, 0, s, size, NULL,
0);
!     if (size > 0 && usize==0)
          return PyErr_SetFromWindowsErrWithFilename(0, NULL);

      v = _PyUnicode_New(usize);
***************
*** 1578,1586 ****
  {
      PyObject *repr;
      char *s;

      /* First get the size of the result */
!     DWORD mbcssize = WideCharToMultiByte(CP_ACP, 0, p, size, NULL,
0, NULL, NULL);
      if (mbcssize==0)
          return PyErr_SetFromWindowsErrWithFilename(0, NULL);

--- 1578,1591 ----
  {
      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 */
!     mbcssize = WideCharToMultiByte(CP_ACP, 0, p, size, NULL, 0,
NULL, NULL);
      if (mbcssize==0)
          return PyErr_SetFromWindowsErrWithFilename(0, NULL);