summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 946faf2..f7297da 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -872,10 +872,10 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
STORE_SIZE(count);
format++;
} else {
- if (strlen(*p) != count)
- return converterr(
- "bytes without null bytes",
- arg, msgbuf, bufsize);
+ if (strlen(*p) != (size_t)count) {
+ PyErr_SetString(PyExc_ValueError, "embedded null byte");
+ RETURN_ERR_OCCURRED;
+ }
}
break;
}
@@ -948,16 +948,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if (sarg == NULL)
return converterr(CONV_UNICODE,
arg, msgbuf, bufsize);
+ if (strlen(sarg) != (size_t)len) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ RETURN_ERR_OCCURRED;
+ }
*p = sarg;
}
else
return converterr(c == 'z' ? "str or None" : "str",
arg, msgbuf, bufsize);
- if (*p != NULL && sarg != NULL && (Py_ssize_t) strlen(*p) != len)
- return converterr(
- c == 'z' ? "str without null characters or None"
- : "str without null characters",
- arg, msgbuf, bufsize);
}
break;
}
@@ -994,10 +993,10 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
*p = PyUnicode_AsUnicodeAndSize(arg, &len);
if (*p == NULL)
RETURN_ERR_OCCURRED;
- if (Py_UNICODE_strlen(*p) != len)
- return converterr(
- "str without null characters or None",
- arg, msgbuf, bufsize);
+ if (Py_UNICODE_strlen(*p) != (size_t)len) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ RETURN_ERR_OCCURRED;
+ }
} else
return converterr(c == 'Z' ? "str or None" : "str",
arg, msgbuf, bufsize);
@@ -1245,7 +1244,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
supports it directly. */
if (PyObject_GetBuffer(arg, (Py_buffer*)p, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
- return converterr("read-write buffer", arg, msgbuf, bufsize);
+ return converterr("read-write bytes-like object",
+ arg, msgbuf, bufsize);
}
if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C')) {
PyBuffer_Release((Py_buffer*)p);
@@ -1283,7 +1283,7 @@ convertbuffer(PyObject *arg, void **p, char **errmsg)
*errmsg = NULL;
*p = NULL;
if (pb != NULL && pb->bf_releasebuffer != NULL) {
- *errmsg = "read-only pinned buffer";
+ *errmsg = "read-only bytes-like object";
return -1;
}
@@ -1299,7 +1299,7 @@ static int
getbuffer(PyObject *arg, Py_buffer *view, char **errmsg)
{
if (PyObject_GetBuffer(arg, view, PyBUF_SIMPLE) != 0) {
- *errmsg = "bytes or buffer";
+ *errmsg = "bytes-like object";
return -1;
}
if (!PyBuffer_IsContiguous(view, 'C')) {