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

Skip to content

Commit 8f53402

Browse files
committed
Merge pull request #5084 from cgohlke/patch-6
Fix segfault in ft2font
2 parents b9710e6 + c57c795 commit 8f53402

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ft2font_wrapper.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
static PyObject *convert_xys_to_array(std::vector<double> &xys)
1111
{
1212
npy_intp dims[] = {(npy_intp)xys.size() / 2, 2 };
13-
return PyArray_SimpleNewFromData(2, dims, NPY_DOUBLE, &xys[0]);
13+
if (dims[0] > 0) {
14+
return PyArray_SimpleNewFromData(2, dims, NPY_DOUBLE, &xys[0]);
15+
} else {
16+
return PyArray_SimpleNew(2, dims, NPY_DOUBLE);
17+
}
1418
}
1519

1620
/**********************************************************************
@@ -664,7 +668,11 @@ static PyObject *PyFT2Font_set_text(PyFT2Font *self, PyObject *args, PyObject *k
664668
return NULL;
665669
}
666670

667-
CALL_CPP("set_text", self->x->set_text(size, &codepoints[0], angle, flags, xys));
671+
uint32_t* codepoints_array = NULL;
672+
if (size > 0) {
673+
codepoints_array = &codepoints[0];
674+
}
675+
CALL_CPP("set_text", self->x->set_text(size, codepoints_array, angle, flags, xys));
668676

669677
return convert_xys_to_array(xys);
670678
}

0 commit comments

Comments
 (0)