[Patches] MBCS codecs fails on zero length string.

Mark Hammond mhammond@skippinet.com.au
Thu, 4 May 2000 09:42:20 +1000


I was obviously having a bad day :-(

It is with great embarrassment and humility that I withdraw my previous
withdrawal of this patch ;-)

The NULL terminator does not come into these routines at all - the exact
number of bytes (which may or may not include the NULL) are converted.
Thus, being asked to encode or decode zero characters is perfectly valid.

I promise in the future that I will wait at least 24 hours between code
changes and patch submissions!

Checkin message:
Mark Hammond should get his act into gear (his words :-).  Zero length
strings _are_ valid!

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.15 unicodeobject.c
*** unicodeobject.c	2000/05/03 12:27:22	2.15
--- unicodeobject.c	2000/05/03 23:41:05
***************
*** 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);