diff options
author | Guido van Rossum <guido@python.org> | 2007-05-09 23:35:09 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-09 23:35:09 (GMT) |
commit | d70539abef79c2ae4ab0c0319a1ee47c10f048dc (patch) | |
tree | bb6fd6d4f88920b235983443b2e9a9a2fc65c958 /Python | |
parent | 6262cc79d70ecf202d5758da1f1361c4d3f9cdc6 (diff) | |
download | cpython-d70539abef79c2ae4ab0c0319a1ee47c10f048dc.zip cpython-d70539abef79c2ae4ab0c0319a1ee47c10f048dc.tar.gz cpython-d70539abef79c2ae4ab0c0319a1ee47c10f048dc.tar.bz2 |
Be more robust around bytes for e[st]#? formats.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/getargs.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 0f6f21b..7b27388 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -915,7 +915,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, PyObject *s; int recode_strings; Py_ssize_t size; - char *ptr; + const char *ptr; /* Get 'e' parameter: the encoding name */ encoding = (const char *)va_arg(*p_va, const char *); @@ -941,11 +941,13 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, arg, msgbuf, bufsize); /* Encode object */ - if (!recode_strings && PyString_Check(arg)) { + if (!recode_strings && + (PyString_Check(arg) || PyBytes_Check(arg))) { s = arg; Py_INCREF(s); - size = PyString_GET_SIZE(s); - ptr = PyString_AS_STRING(s); + if (PyObject_AsCharBuffer(s, &ptr, &size) < 0) + return converterr("(AsCharBuffer failed)", + arg, msgbuf, bufsize); } else { PyObject *u; @@ -973,6 +975,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, } size = PyBytes_GET_SIZE(s); ptr = PyBytes_AS_STRING(s); + if (ptr == NULL) + ptr = ""; } /* Write output; output is guaranteed to be 0-terminated */ |