Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89ec5c8

Browse files
committed
Move REFCNT check to realloc function
1 parent 08ef20c commit 89ec5c8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/cstring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ static PyObject *_cstring_new(PyTypeObject *type, const char *value, Py_ssize_t
3737
}
3838

3939
static PyObject *_cstring_realloc(PyObject *self, Py_ssize_t len) {
40+
if(Py_REFCNT(self) > 1)
41+
return PyErr_BadInternalCall(), NULL;
4042
struct cstring *new = (struct cstring *)PyObject_Realloc(self, sizeof(struct cstring) + len + 1);
4143
if(!new)
4244
return PyErr_NoMemory();
@@ -170,8 +172,6 @@ static PyObject *_concat_in_place(PyObject *self, PyObject *other) {
170172
return _cstring_copy(other); /* new (mutable) copy with refcnt=1 */
171173
if(!_ensure_cstring(self))
172174
return NULL;
173-
if(Py_REFCNT(self) > 1)
174-
return PyErr_BadInternalCall(), NULL;
175175

176176
Py_ssize_t origlen = cstring_len(self);
177177
Py_ssize_t newlen = origlen + cstring_len(other);

0 commit comments

Comments
 (0)