summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2003-11-06 20:47:57 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2003-11-06 20:47:57 (GMT)
commitd2171d2ba414def2ecf27b694ea27c2e9fde0fcf (patch)
treef61634cce466b7725ad365981234cf38d6a49a84 /Modules
parent85c20a41dfcec04d161ad7da7260e7b94c62d228 (diff)
downloadcpython-d2171d2ba414def2ecf27b694ea27c2e9fde0fcf.zip
cpython-d2171d2ba414def2ecf27b694ea27c2e9fde0fcf.tar.gz
cpython-d2171d2ba414def2ecf27b694ea27c2e9fde0fcf.tar.bz2
Overallocate target buffer for normalization more early. Fixes #834676.
Backported to 2.3.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/unicodedata.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index d266ad7..311db29 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -311,12 +311,14 @@ nfd_nfkd(PyObject *input, int k)
stack[stackptr++] = *i++;
while(stackptr) {
Py_UNICODE code = stack[--stackptr];
- if (!space) {
- space = PyString_GET_SIZE(result) + 10;
- if (PyUnicode_Resize(&result, space) == -1)
+ /* Hangul Decomposition adds three characters in
+ a single step, so we need atleast that much room. */
+ if (space < 3) {
+ int newsize = PyString_GET_SIZE(result) + 10;
+ space += 10;
+ if (PyUnicode_Resize(&result, newsize) == -1)
return NULL;
- o = PyUnicode_AS_UNICODE(result) + space - 10;
- space = 10;
+ o = PyUnicode_AS_UNICODE(result) + newsize - space;
}
/* Hangul Decomposition. */
if (SBase <= code && code < (SBase+SCount)) {