_PyUnicodeWriter: assert that max character <= MAX_UNICODE

This commit is contained in:
Victor Stinner 2016-09-06 16:58:36 -07:00
parent c083476bde
commit 2740e46089
1 changed files with 3 additions and 0 deletions

View File

@ -13348,6 +13348,8 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
Py_ssize_t newlen; Py_ssize_t newlen;
PyObject *newbuffer; PyObject *newbuffer;
assert(maxchar <= MAX_UNICODE);
/* ensure that the _PyUnicodeWriter_Prepare macro was used */ /* ensure that the _PyUnicodeWriter_Prepare macro was used */
assert((maxchar > writer->maxchar && length >= 0) assert((maxchar > writer->maxchar && length >= 0)
|| length > 0); || length > 0);
@ -13441,6 +13443,7 @@ _PyUnicodeWriter_PrepareKindInternal(_PyUnicodeWriter *writer,
Py_LOCAL_INLINE(int) Py_LOCAL_INLINE(int)
_PyUnicodeWriter_WriteCharInline(_PyUnicodeWriter *writer, Py_UCS4 ch) _PyUnicodeWriter_WriteCharInline(_PyUnicodeWriter *writer, Py_UCS4 ch)
{ {
assert(ch <= MAX_UNICODE);
if (_PyUnicodeWriter_Prepare(writer, 1, ch) < 0) if (_PyUnicodeWriter_Prepare(writer, 1, ch) < 0)
return -1; return -1;
PyUnicode_WRITE(writer->kind, writer->data, writer->pos, ch); PyUnicode_WRITE(writer->kind, writer->data, writer->pos, ch);