Skip to content

Commit

Permalink
Use calloc instead of malloc for vtable allocation.
Browse files Browse the repository at this point in the history
Calloc is better for allocating arrays as it does not have issue
with overflow.
  • Loading branch information
igo95862 committed Feb 6, 2021
1 parent 37ea44c commit 316c4b0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/sdbus/sd_bus_internals.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@
return NULL; \
}

#define CALL_SD_BUS_AND_CHECK(sd_bus_function) \
({ \
int return_int = sd_bus_function; \
if (return_int < 0) \
{ \
#define CALL_SD_BUS_AND_CHECK(sd_bus_function) \
({ \
int return_int = sd_bus_function; \
if (return_int < 0) \
{ \
PyErr_Format(exception_lib, "Line: %d. " #sd_bus_function " in function %s returned error: %s", \
__LINE__, __FUNCTION__, strerrorname_np(-return_int)); \
return NULL; \
} \
return_int; \
__LINE__, __FUNCTION__, strerrorname_np(-return_int)); \
return NULL; \
} \
return_int; \
})

#define CALL_SD_BUS_CHECK_RETURN_NEG1(sd_bus_function) \
Expand Down Expand Up @@ -413,7 +413,7 @@ SdBusInterface_create_vtable(SdBusInterfaceObject *self,
Py_ssize_t num_of_properties = PyList_Size(self->property_list);
Py_ssize_t num_of_signals = PyList_Size(self->signal_list);

self->vtable = malloc(sizeof(sd_bus_vtable) * (num_of_signals + num_of_properties + num_of_methods + 2));
self->vtable = calloc(num_of_signals + num_of_properties + num_of_methods + 2, sizeof(sd_bus_vtable));
if (self->vtable == NULL)
{
return PyErr_NoMemory();
Expand Down

0 comments on commit 316c4b0

Please sign in to comment.