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

Skip to content

Commit 07b63a3

Browse files
committed
Fix segfault in ft2font
1 parent db80e29 commit 07b63a3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/ft2font_wrapper.cpp

Lines changed: 8 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,9 @@ 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+
if (size > 0) {
672+
CALL_CPP("set_text", self->x->set_text(size, &codepoints[0], angle, flags, xys));
673+
}
668674

669675
return convert_xys_to_array(xys);
670676
}

0 commit comments

Comments
 (0)