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:
parent
666752d521
commit
6adf19b52f
2 changed files with 8 additions and 3 deletions
|
|
@ -43,8 +43,11 @@ SWIG_Python_str_AsChar(PyObject *str)
|
||||||
if (str) {
|
if (str) {
|
||||||
char *cstr;
|
char *cstr;
|
||||||
Py_ssize_t len;
|
Py_ssize_t len;
|
||||||
PyBytes_AsStringAndSize(str, &cstr, &len);
|
if (PyBytes_AsStringAndSize(str, &cstr, &len) == -1)
|
||||||
|
return NULL;
|
||||||
newstr = (char *) malloc(len+1);
|
newstr = (char *) malloc(len+1);
|
||||||
|
if (!newstr)
|
||||||
|
return NULL;
|
||||||
memcpy(newstr, cstr, len+1);
|
memcpy(newstr, cstr, len+1);
|
||||||
Py_XDECREF(str);
|
Py_XDECREF(str);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,11 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
||||||
if (alloc)
|
if (alloc)
|
||||||
*alloc = SWIG_NEWOBJ;
|
*alloc = SWIG_NEWOBJ;
|
||||||
%#endif
|
%#endif
|
||||||
PyBytes_AsStringAndSize(obj, &cstr, &len);
|
if (PyBytes_AsStringAndSize(obj, &cstr, &len) == -1)
|
||||||
|
return SWIG_TypeError;
|
||||||
%#else
|
%#else
|
||||||
PyString_AsStringAndSize(obj, &cstr, &len);
|
if (PyString_AsStringAndSize(obj, &cstr, &len) == -1)
|
||||||
|
return SWIG_TypeError;
|
||||||
%#endif
|
%#endif
|
||||||
if (cptr) {
|
if (cptr) {
|
||||||
if (alloc) {
|
if (alloc) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue