Skip to content

Commit

Permalink
Properly size memory blocks in units of wchar_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
loewis committed Mar 8, 2008
1 parent 92fab75 commit a69e1ef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ str2uni(const char* s)
if (needed < sizeof(smallbuf))
dest = smallbuf;
else {
dest = PyMem_Malloc(needed+1);
dest = PyMem_Malloc((needed+1)*sizeof(wchar_t));
if (!dest)
return PyErr_NoMemory();
}
Expand Down Expand Up @@ -282,7 +282,7 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
#ifdef HAVE_USABLE_WCHAR_T
s = s0;
#else
s = PyMem_Malloc(n0+1);
s = PyMem_Malloc((n0+1)*sizeof(wchar_t));
if (!s)
return PyErr_NoMemory();
for (i=0; i<=n0; i++)
Expand All @@ -291,15 +291,15 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)

/* assume no change in size, first */
n1 = wcslen(s) + 1;
buf = PyMem_Malloc(n1);
buf = PyMem_Malloc(n1*sizeof(wchar_t));
if (!buf) {
PyErr_NoMemory();
goto exit;
}
n2 = wcsxfrm(buf, s, n1);
if (n2 >= n1) {
/* more space needed */
buf = PyMem_Realloc(buf, n2+1);
buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t));
if (!buf) {
PyErr_NoMemory();
goto exit;
Expand Down

0 comments on commit a69e1ef

Please sign in to comment.