summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-03-02 16:18:56 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-03-02 16:18:56 (GMT)
commit83d8fc265a962a4bdec76c34396a6eb83e961fcd (patch)
treeee3501fed4415e243cae6f2344082d8254e67ff9 /Modules
parent4e02f8f4aec46ffba087e525188a6429a155b8f9 (diff)
parent5061e67f0f6e08e99b2ca3b560cd64d8cc5aa515 (diff)
downloadcpython-83d8fc265a962a4bdec76c34396a6eb83e961fcd.zip
cpython-83d8fc265a962a4bdec76c34396a6eb83e961fcd.tar.gz
cpython-83d8fc265a962a4bdec76c34396a6eb83e961fcd.tar.bz2
merge 3.4 (#23367)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/unicodedata.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 47d2937..507cef3 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -553,10 +553,17 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
stackptr = 0;
isize = PyUnicode_GET_LENGTH(input);
+ space = isize;
/* Overallocate at most 10 characters. */
- space = (isize > 10 ? 10 : isize) + isize;
+ if (space > 10) {
+ if (space <= PY_SSIZE_T_MAX - 10)
+ space += 10;
+ }
+ else {
+ space *= 2;
+ }
osize = space;
- output = PyMem_New(Py_UCS4, space);
+ output = PyMem_NEW(Py_UCS4, space);
if (!output) {
PyErr_NoMemory();
return NULL;
@@ -703,7 +710,7 @@ nfc_nfkc(PyObject *self, PyObject *input, int k)
/* We allocate a buffer for the output.
If we find that we made no changes, we still return
the NFD result. */
- output = PyMem_New(Py_UCS4, len);
+ output = PyMem_NEW(Py_UCS4, len);
if (!output) {
PyErr_NoMemory();
Py_DECREF(result);