diff options
author | Simon Ser <contact@emersion.fr> | 2023-08-03 12:07:27 +0200 |
---|---|---|
committer | Alexander Orzechowski <alex@ozal.ski> | 2023-08-03 14:40:28 +0000 |
commit | c74f89d4f84bfed0284d3908aee5d207698c70c5 (patch) | |
tree | 6ded2e7ac9010daf75437ffd6ad45f0659412bbf | |
parent | 77dc1c28aa551616521b60f1a8727a25a45f82e1 (diff) |
Avoid using memcpy() to copy structs
We can just use a regular assignment instead. This is more
type-safe since there is no need to provide the struct size.
The remaining memcpy() calls perform array copies or copies from
void pointers (which may be unaligned).
-rw-r--r-- | render/allocator/drm_dumb.c | 2 | ||||
-rw-r--r-- | render/allocator/gbm.c | 4 | ||||
-rw-r--r-- | render/allocator/shm.c | 2 | ||||
-rw-r--r-- | render/dmabuf.c | 2 | ||||
-rw-r--r-- | types/wlr_compositor.c | 2 | ||||
-rw-r--r-- | types/wlr_linux_dmabuf_v1.c | 2 |
6 files changed, 7 insertions, 7 deletions
diff --git a/render/allocator/drm_dumb.c b/render/allocator/drm_dumb.c index 03ff8e3f..6de44f40 100644 --- a/render/allocator/drm_dumb.c +++ b/render/allocator/drm_dumb.c @@ -129,7 +129,7 @@ static void drm_dumb_buffer_end_data_ptr_access(struct wlr_buffer *wlr_buffer) { static bool buffer_get_dmabuf(struct wlr_buffer *wlr_buffer, struct wlr_dmabuf_attributes *attribs) { struct wlr_drm_dumb_buffer *buf = drm_dumb_buffer_from_buffer(wlr_buffer); - memcpy(attribs, &buf->dmabuf, sizeof(buf->dmabuf)); + *attribs = buf->dmabuf; return true; } diff --git a/render/allocator/gbm.c b/render/allocator/gbm.c index 32636d30..25ddbbae 100644 --- a/render/allocator/gbm.c +++ b/render/allocator/gbm.c @@ -79,7 +79,7 @@ static bool export_gbm_bo(struct gbm_bo *bo, attribs.stride[i] = gbm_bo_get_stride_for_plane(bo, i); } - memcpy(out, &attribs, sizeof(attribs)); + *out = attribs; return true; error_fd: @@ -168,7 +168,7 @@ static bool buffer_get_dmabuf(struct wlr_buffer *wlr_buffer, struct wlr_dmabuf_attributes *attribs) { struct wlr_gbm_buffer *buffer = get_gbm_buffer_from_buffer(wlr_buffer); - memcpy(attribs, &buffer->dmabuf, sizeof(buffer->dmabuf)); + *attribs = buffer->dmabuf; return true; } diff --git a/render/allocator/shm.c b/render/allocator/shm.c index b6d3138c..2622f99a 100644 --- a/render/allocator/shm.c +++ b/render/allocator/shm.c @@ -31,7 +31,7 @@ static void buffer_destroy(struct wlr_buffer *wlr_buffer) { static bool buffer_get_shm(struct wlr_buffer *wlr_buffer, struct wlr_shm_attributes *shm) { struct wlr_shm_buffer *buffer = shm_buffer_from_buffer(wlr_buffer); - memcpy(shm, &buffer->shm, sizeof(*shm)); + *shm = buffer->shm; return true; } diff --git a/render/dmabuf.c b/render/dmabuf.c index 44b840f2..b0b8ef41 100644 --- a/render/dmabuf.c +++ b/render/dmabuf.c @@ -15,7 +15,7 @@ void wlr_dmabuf_attributes_finish(struct wlr_dmabuf_attributes *attribs) { bool wlr_dmabuf_attributes_copy(struct wlr_dmabuf_attributes *dst, const struct wlr_dmabuf_attributes *src) { - memcpy(dst, src, sizeof(struct wlr_dmabuf_attributes)); + *dst = *src; int i; for (i = 0; i < src->n_planes; ++i) { diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index bf61f74a..68a7c229 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -330,7 +330,7 @@ static void surface_state_move(struct wlr_surface_state *state, pixman_region32_copy(&state->input, &next->input); } if (next->committed & WLR_SURFACE_STATE_VIEWPORT) { - memcpy(&state->viewport, &next->viewport, sizeof(state->viewport)); + state->viewport = next->viewport; } if (next->committed & WLR_SURFACE_STATE_FRAME_CALLBACK_LIST) { wl_list_insert_list(&state->frame_callback_list, diff --git a/types/wlr_linux_dmabuf_v1.c b/types/wlr_linux_dmabuf_v1.c index 48dc9a34..54e2338f 100644 --- a/types/wlr_linux_dmabuf_v1.c +++ b/types/wlr_linux_dmabuf_v1.c @@ -111,7 +111,7 @@ static bool buffer_get_dmabuf(struct wlr_buffer *wlr_buffer, struct wlr_dmabuf_attributes *attribs) { struct wlr_dmabuf_v1_buffer *buffer = dmabuf_v1_buffer_from_buffer(wlr_buffer); - memcpy(attribs, &buffer->attributes, sizeof(buffer->attributes)); + *attribs = buffer->attributes; return true; } |