[Python-checkins] cpython (merge 3.6 -> default): Add an extra byte for null in case we ever get very long unicode names.

christian.heimes python-checkins at python.org
Fri Sep 23 14:25:04 EDT 2016


https://hg.python.org/cpython/rev/3d2ea746d4b6
changeset:   104033:3d2ea746d4b6
parent:      104030:bb11a3aef5b0
parent:      104032:fd78cc221ec6
user:        Christian Heimes <christian at python.org>
date:        Fri Sep 23 20:21:27 2016 +0200
summary:
  Add an extra byte for null in case we ever get very long unicode names.

files:
  Modules/unicodedata.c |  8 ++++----
  1 files changed, 4 insertions(+), 4 deletions(-)


diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -1044,8 +1044,8 @@
 {
     /* check if code corresponds to the given name */
     int i;
-    char buffer[NAME_MAXLEN];
-    if (!_getucname(self, code, buffer, sizeof(buffer), 1))
+    char buffer[NAME_MAXLEN+1];
+    if (!_getucname(self, code, buffer, NAME_MAXLEN, 1))
         return 0;
     for (i = 0; i < namelen; i++) {
         if (Py_TOUPPER(Py_CHARMASK(name[i])) != buffer[i])
@@ -1198,10 +1198,10 @@
 unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value)
 /*[clinic end generated code: output=6bbb37a326407707 input=3e0367f534de56d9]*/
 {
-    char name[NAME_MAXLEN];
+    char name[NAME_MAXLEN+1];
     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) {
             PyErr_SetString(PyExc_ValueError, "no such name");
             return NULL;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list