From c74f89d4f84bfed0284d3908aee5d207698c70c5 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 3 Aug 2023 12:07:27 +0200 Subject: 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). --- render/allocator/drm_dumb.c | 2 +- render/allocator/gbm.c | 4 ++-- render/allocator/shm.c | 2 +- render/dmabuf.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'render') 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) { -- cgit v1.2.3