python4yahdlc icon indicating copy to clipboard operation
python4yahdlc copied to clipboard

Segmentation fault on accessing const char *send_data in static PyObject *frame_data(PyObject *self, PyObject *args)

Open rlbjorn opened this issue 1 year ago • 1 comments

static PyObject *frame_data(PyObject *self, PyObject *args) and static PyObject *get_data(PyObject *self, PyObject *args) both declare a const char* array which PyArg_ParseTuple is supposed to populate. The behavior seems undefined as this works on my windows computer, but not on the mac.

Allocating a size for the c arrays fixes the issue, f.ex: const char send_data[255]; instead of const char *send_data

rlbjorn avatar Jun 26 '24 10:06 rlbjorn

I got it working correctly on both arm mac and windows by using the safer specifer z#, instead of s# in if (!PyArg_ParseTuple(args, "z#|II", &send_data, &data_length, &frame_type, &seq_no)) and if (!PyArg_ParseTuple(args, "z#", &frame_data, &buf_length))

using Py_ssize_t for buf_length/data_length

z# actually allocates the memory if i understood it correctly, while s# does not.

rlbjorn avatar Jun 26 '24 11:06 rlbjorn