Skip to content

Commit

Permalink
python: Fix pd_info builder after const qualification of info->cap
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Nov 20, 2023
1 parent 5614690 commit 509dab7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions python/pyosdp_pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static int pyosdp_add_pd_cap(PyObject *obj, osdp_pd_info_t *info)
{
PyObject *py_pd_cap;
int i, cap_list_size, function_code, compliance_level, num_items;
struct osdp_pd_cap *cap;

cap_list_size = (int)PyList_Size(obj);
if (cap_list_size == 0)
Expand All @@ -192,8 +193,8 @@ static int pyosdp_add_pd_cap(PyObject *obj, osdp_pd_info_t *info)
return -1;
}

info->cap = calloc(cap_list_size + 1, sizeof(struct osdp_pd_cap));
if (info->cap == NULL) {
cap = calloc(cap_list_size + 1, sizeof(struct osdp_pd_cap));
if (cap == NULL) {
PyErr_SetString(PyExc_MemoryError, "pd cap alloc error");
return -1;
}
Expand All @@ -212,10 +213,11 @@ static int pyosdp_add_pd_cap(PyObject *obj, osdp_pd_info_t *info)
if (pyosdp_dict_get_int(py_pd_cap, "num_items", &num_items))
return -1;

info->cap[i].function_code = (uint8_t)function_code;
info->cap[i].compliance_level = (uint8_t)compliance_level;
info->cap[i].num_items = (uint8_t)num_items;
cap[i].function_code = (uint8_t)function_code;
cap[i].compliance_level = (uint8_t)compliance_level;
cap[i].num_items = (uint8_t)num_items;
}
info->cap = cap;

return 0;
}
Expand Down Expand Up @@ -324,12 +326,12 @@ static int pyosdp_pd_tp_init(pyosdp_pd_t *self, PyObject *args, PyObject *kwargs
self->ctx = ctx;
safe_free(channel_type_str);
safe_free(device);
safe_free(info.cap);
safe_free((void *)info.cap);
return 0;
error:
safe_free(channel_type_str);
safe_free(device);
safe_free(info.cap);
safe_free((void *)info.cap);
return -1;
}

Expand Down

0 comments on commit 509dab7

Please sign in to comment.