Use [0] to get element size when allocating arrays

This is clearer than using * or hardcoding a type.
This commit is contained in:
Simon Ser 2024-05-15 12:00:31 +02:00
parent 4e11884228
commit 0c65405d54
2 changed files with 4 additions and 4 deletions

View file

@ -947,8 +947,8 @@ liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req,
result.flags = flags;
result.planes_len = liftoff_list_length(&device->planes);
step.alloc = malloc(result.planes_len * sizeof(*step.alloc));
result.best = malloc(result.planes_len * sizeof(*result.best));
step.alloc = malloc(result.planes_len * sizeof(step.alloc[0]));
result.best = malloc(result.planes_len * sizeof(result.best[0]));
if (step.alloc == NULL || result.best == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "malloc");
return -ENOMEM;

View file

@ -77,8 +77,8 @@ liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
prop = layer_get_property(layer, name);
if (prop == NULL) {
props = realloc(layer->props, (layer->props_len + 1)
* sizeof(struct liftoff_layer_property));
props = realloc(layer->props,
(layer->props_len + 1) * sizeof(props[0]));
if (props == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "realloc");
return -ENOMEM;