Check Py{Bytes,String}_AsStringAndSize() for failure

PyBytes_AsStringAndSize() and PyString_AsStringAndSize() were not
being checked for failure.

Closes #1349.
This commit is contained in:
Zackery Spytz 2020-01-09 21:14:12 -07:00
commit 6adf19b52f
2 changed files with 8 additions and 3 deletions

View file

@ -43,8 +43,11 @@ SWIG_Python_str_AsChar(PyObject *str)
if (str) {
char *cstr;
Py_ssize_t len;
PyBytes_AsStringAndSize(str, &cstr, &len);
if (PyBytes_AsStringAndSize(str, &cstr, &len) == -1)
return NULL;
newstr = (char *) malloc(len+1);
if (!newstr)
return NULL;
memcpy(newstr, cstr, len+1);
Py_XDECREF(str);
}