Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b2a762

Browse filesBrowse files
committed
Don't copy string
1 parent 3f51ef5 commit 1b2a762
Copy full SHA for 1b2a762

File tree

Expand file treeCollapse file tree

1 file changed

+17
-8
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-8
lines changed

‎src/_path_wrapper.cpp

Copy file name to clipboardExpand all lines: src/_path_wrapper.cpp
+17-8Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,24 +674,33 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
674674
}
675675

676676
size_t buffersize = path.total_vertices() * (precision + 5) * 4;
677-
std::string buffer;
678-
buffer.reserve(buffersize);
677+
PyObject *bufferobj = PyBytes_FromStringAndSize(NULL, buffersize);
678+
if (bufferobj == NULL) {
679+
return NULL;
680+
}
681+
char *buffer = PyBytes_AsString(bufferobj);
679682

680683
CALL_CPP("convert_to_string",
681684
(status = convert_to_string(
682685
path, trans, cliprect, simplify, sketch,
683-
precision, codes, (bool)postfix, &buffer[0],
686+
precision, codes, (bool)postfix, buffer,
684687
&buffersize)));
685688

686-
if (status == 1) {
687-
PyErr_SetString(PyExc_MemoryError, "Buffer overflow");
689+
if (status) {
690+
Py_DECREF(bufferobj);
691+
if (status == 1) {
692+
PyErr_SetString(PyExc_MemoryError, "Buffer overflow");
693+
} else if (status == 2) {
694+
PyErr_SetString(PyExc_ValueError, "Malformed path codes");
695+
}
688696
return NULL;
689-
} else if (status == 2) {
690-
PyErr_SetString(PyExc_ValueError, "Malformed path codes");
697+
}
698+
699+
if (_PyBytes_Resize(&bufferobj, buffersize)) {
691700
return NULL;
692701
}
693702

694-
return PyBytes_FromStringAndSize(&buffer[0], buffersize);
703+
return bufferobj;
695704
}
696705

697706
extern "C" {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.