}
static int
-unicode_widen(PyObject **p_unicode, unsigned int maxchar)
+unicode_widen(PyObject **p_unicode, Py_ssize_t length,
+ unsigned int maxchar)
{
PyObject *result;
assert(PyUnicode_IS_READY(*p_unicode));
+ assert(length <= PyUnicode_GET_LENGTH(*p_unicode));
if (maxchar <= PyUnicode_MAX_CHAR_VALUE(*p_unicode))
return 0;
result = PyUnicode_New(PyUnicode_GET_LENGTH(*p_unicode),
maxchar);
if (result == NULL)
return -1;
- PyUnicode_CopyCharacters(result, 0, *p_unicode, 0,
- PyUnicode_GET_LENGTH(*p_unicode));
+ PyUnicode_CopyCharacters(result, 0, *p_unicode, 0, length);
Py_DECREF(*p_unicode);
*p_unicode = result;
return 0;
Py_UCS4 ch)
{
assert(ch <= MAX_UNICODE);
- if (unicode_widen(p_unicode, ch) < 0)
+ if (unicode_widen(p_unicode, *pos, ch) < 0)
return -1;
PyUnicode_WRITE(PyUnicode_KIND(*p_unicode),
PyUnicode_DATA(*p_unicode),
if (unicode_resize(output, requiredsize) < 0)
goto onError;
}
- if (unicode_widen(output, PyUnicode_MAX_CHAR_VALUE(repunicode)) < 0)
+ if (unicode_widen(output, *outpos,
+ PyUnicode_MAX_CHAR_VALUE(repunicode)) < 0)
goto onError;
copy_characters(*output, *outpos, repunicode, 0, replen);
*outpos += replen;
maxch = MAX_MAXCHAR(maxch, ch);
#endif
if (maxch > PyUnicode_MAX_CHAR_VALUE(unicode)) {
- if (unicode_widen(&unicode, maxch) < 0)
+ if (unicode_widen(&unicode, outpos, maxch) < 0)
goto onError;
kind = PyUnicode_KIND(unicode);
data = PyUnicode_DATA(unicode);
goto onError;
}
}
- if (unicode_widen(&v, PyUnicode_MAX_CHAR_VALUE(x)) < 0)
+ if (unicode_widen(&v, outpos, PyUnicode_MAX_CHAR_VALUE(x)) < 0)
goto onError;
PyUnicode_CopyCharacters(v, outpos, x, 0, targetsize);
outpos += targetsize;