aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-08-03 12:07:27 +0200
committerAlexander Orzechowski <alex@ozal.ski>2023-08-03 14:40:28 +0000
commitc74f89d4f84bfed0284d3908aee5d207698c70c5 (patch)
tree6ded2e7ac9010daf75437ffd6ad45f0659412bbf /render
parent77dc1c28aa551616521b60f1a8727a25a45f82e1 (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).
Diffstat (limited to 'render')
-rw-r--r--render/allocator/drm_dumb.c2
-rw-r--r--render/allocator/gbm.c4
-rw-r--r--render/allocator/shm.c2
-rw-r--r--render/dmabuf.c2
4 files changed, 5 insertions, 5 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) {