diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/getargs.c | 7 | ||||
-rw-r--r-- | Python/modsupport.c | 19 |
2 files changed, 19 insertions, 7 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 7b2738834a..1730bff1ff 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -761,15 +761,14 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, #endif /* WITHOUT_COMPLEX */ case 'c': {/* char */ - char *p = va_arg(*p_va, char *); + int *p = va_arg(*p_va, int *); if (PyString_Check(arg) && PyString_Size(arg) == 1) *p = PyString_AS_STRING(arg)[0]; else if (PyUnicode_Check(arg) && - PyUnicode_GET_SIZE(arg) == 1 && - PyUnicode_AS_UNICODE(arg)[0] < 256) + PyUnicode_GET_SIZE(arg) == 1) *p = PyUnicode_AS_UNICODE(arg)[0]; else - return converterr("char < 256", arg, msgbuf, bufsize); + return converterr("char", arg, msgbuf, bufsize); break; } diff --git a/Python/modsupport.c b/Python/modsupport.c index 781a331493..ba464099dd 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -385,9 +385,22 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) case 'c': { - char p[1]; - p[0] = (char)va_arg(*p_va, int); - return PyString_FromStringAndSize(p, 1); + int i = va_arg(*p_va, int); + Py_UNICODE c; + if (i < 0 || i > PyUnicode_GetMax()) { +#ifdef Py_UNICODE_WIDE + PyErr_SetString(PyExc_OverflowError, + "%c arg not in range(0x110000) " + "(wide Python build)"); +#else + PyErr_SetString(PyExc_OverflowError, + "%c arg not in range(0x10000) " + "(narrow Python build)"); +#endif + return NULL; + } + c = i; + return PyUnicode_FromUnicode(&c, 1); } case 's': |