mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +00:00
No functional change. Add comment and assert to describe why there cannot be overflow which was reported by Klocwork. Discussed on python-dev
This commit is contained in:
parent
101bac205d
commit
37f694f21b
1 changed files with 9 additions and 2 deletions
|
|
@ -395,6 +395,7 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
|
||||||
PyUnicodeObject *v;
|
PyUnicodeObject *v;
|
||||||
char decomp[256];
|
char decomp[256];
|
||||||
int code, index, count, i;
|
int code, index, count, i;
|
||||||
|
unsigned int prefix_index;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O!:decomposition",
|
if (!PyArg_ParseTuple(args, "O!:decomposition",
|
||||||
&PyUnicode_Type, &v))
|
&PyUnicode_Type, &v))
|
||||||
|
|
@ -428,9 +429,15 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
|
||||||
/* XXX: could allocate the PyString up front instead
|
/* XXX: could allocate the PyString up front instead
|
||||||
(strlen(prefix) + 5 * count + 1 bytes) */
|
(strlen(prefix) + 5 * count + 1 bytes) */
|
||||||
|
|
||||||
|
/* Based on how index is calculated above and decomp_data is generated
|
||||||
|
from Tools/unicode/makeunicodedata.py, it should not be possible
|
||||||
|
to overflow decomp_prefix. */
|
||||||
|
prefix_index = decomp_data[index] & 255;
|
||||||
|
assert(prefix_index < (sizeof(decomp_prefix)/sizeof(*decomp_prefix)));
|
||||||
|
|
||||||
/* copy prefix */
|
/* copy prefix */
|
||||||
i = strlen(decomp_prefix[decomp_data[index] & 255]);
|
i = strlen(decomp_prefix[prefix_index]);
|
||||||
memcpy(decomp, decomp_prefix[decomp_data[index] & 255], i);
|
memcpy(decomp, decomp_prefix[prefix_index], i);
|
||||||
|
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
if (i)
|
if (i)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue