summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-10-03 19:27:00 +0000
committerAndrew M. Kuchling <amk@amk.ca>2006-10-03 19:27:00 +0000
commitcc17b6f005a151b685361661e545f9e0caa1beb9 (patch)
tree2515159e9e016b6a9736124f8fb273042494052a /Modules
parentc45e5d9d91b40d2bd71990530f3aaec1534f23f8 (diff)
downloadcpython-git-cc17b6f005a151b685361661e545f9e0caa1beb9.tar.gz
[Backport r50858 | neal.norwitz]
No functional change. Add comment and assert to describe why there cannot be overflow which was reported by Klocwork. Discussed on python-dev.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/unicodedata.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 85f5f5f9df..2f97df1978 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -230,6 +230,7 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
PyUnicodeObject *v;
char decomp[256];
int code, index, count, i;
+ unsigned int prefix_index;
if (!PyArg_ParseTuple(args, "O!:decomposition",
&PyUnicode_Type, &v))
@@ -257,9 +258,15 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
/* XXX: could allocate the PyString up front instead
(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 */
- i = strlen(decomp_prefix[decomp_data[index] & 255]);
- memcpy(decomp, decomp_prefix[decomp_data[index] & 255], i);
+ i = strlen(decomp_prefix[prefix_index]);
+ memcpy(decomp, decomp_prefix[prefix_index], i);
while (count-- > 0) {
if (i)