diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-11 08:09:54 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-11 08:09:54 +0400 |
commit | a4d5ef8c7d6b8d1e73126b124aad3b4580370fa3 (patch) | |
tree | 8f6b98b4e7d4f3909afffdbe1e3e1e86cb4d3b01 /source | |
parent | d0569dd68ed116b6d1998c9712875c6abafa1875 (diff) |
fix for bpy.props string get-length callback, PyUnicode_GetLength() isn't a measure of the buffer size.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index 8769700f32c..f3fa0c9a0a9 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -974,20 +974,18 @@ static void bpy_prop_string_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p printf_func_error(py_func); value[0] = '\0'; } + else if (!PyUnicode_Check(ret)) { + PyErr_Format(PyExc_TypeError, + "return value must be a string, not %.200s", + Py_TYPE(ret)->tp_name); + printf_func_error(py_func); + value[0] = '\0'; + Py_DECREF(ret); + } else { Py_ssize_t length; const char *buffer = _PyUnicode_AsStringAndSize(ret, &length); - - if (!buffer) { - if (PyErr_Occurred()) { /* should always be true */ - printf_func_error(py_func); - } - value[0] = '\0'; - } - else { - memcpy(value, buffer, length + 1); - } - + memcpy(value, buffer, length + 1); Py_DECREF(ret); } @@ -1034,9 +1032,20 @@ static int bpy_prop_string_length_cb(struct PointerRNA *ptr, struct PropertyRNA if (ret == NULL) { printf_func_error(py_func); + length = 0; + } + else if (!PyUnicode_Check(ret)) { + PyErr_Format(PyExc_TypeError, + "return value must be a string, not %.200s", + Py_TYPE(ret)->tp_name); + printf_func_error(py_func); + length = 0; + Py_DECREF(ret); } else { - length = PyUnicode_GetLength(ret); + Py_ssize_t length_ssize_t = 0; + _PyUnicode_AsStringAndSize(ret, &length_ssize_t); + length = length_ssize_t; Py_DECREF(ret); } |