Add an extra byte for null in case we ever get very long unicode names.

This commit is contained in:
Christian Heimes 2016-09-23 20:21:27 +02:00
commit 4e8fa31029
1 changed files with 4 additions and 4 deletions

View File

@ -1044,8 +1044,8 @@ _cmpname(PyObject *self, int code, const char* name, int namelen)
{ {
/* check if code corresponds to the given name */ /* check if code corresponds to the given name */
int i; int i;
char buffer[NAME_MAXLEN]; char buffer[NAME_MAXLEN+1];
if (!_getucname(self, code, buffer, sizeof(buffer), 1)) if (!_getucname(self, code, buffer, NAME_MAXLEN, 1))
return 0; return 0;
for (i = 0; i < namelen; i++) { for (i = 0; i < namelen; i++) {
if (Py_TOUPPER(Py_CHARMASK(name[i])) != buffer[i]) if (Py_TOUPPER(Py_CHARMASK(name[i])) != buffer[i])
@ -1198,10 +1198,10 @@ static PyObject *
unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value) unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value)
/*[clinic end generated code: output=6bbb37a326407707 input=3e0367f534de56d9]*/ /*[clinic end generated code: output=6bbb37a326407707 input=3e0367f534de56d9]*/
{ {
char name[NAME_MAXLEN]; char name[NAME_MAXLEN+1];
Py_UCS4 c = (Py_UCS4)chr; Py_UCS4 c = (Py_UCS4)chr;
if (!_getucname(self, c, name, sizeof(name), 0)) { if (!_getucname(self, c, name, NAME_MAXLEN, 0)) {
if (default_value == NULL) { if (default_value == NULL) {
PyErr_SetString(PyExc_ValueError, "no such name"); PyErr_SetString(PyExc_ValueError, "no such name");
return NULL; return NULL;