From ce325b1ee60c1a0c501bdff4bf3636635881063f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 16 Feb 2023 21:33:36 +0100 Subject: [PATCH] Turn on -Wsign-conversion References: https://gitlab.freedesktop.org/emersion/libliftoff/-/issues/74 --- device.c | 9 ++++----- example/common.c | 2 +- example/compositor.c | 22 +++++++++++----------- example/dynamic.c | 6 +++--- example/multi-output.c | 8 ++++---- example/simple.c | 8 ++++---- layer.c | 2 +- meson.build | 1 + output.c | 4 ++-- plane.c | 6 +++--- test/bench.c | 18 +++++++++--------- test/libdrm_mock.c | 2 +- test/libdrm_mock.h | 2 +- test/test_alloc.c | 16 ++++++++-------- test/test_candidate.c | 12 ++++++------ test/test_dynamic.c | 12 ++++++------ test/test_priority.c | 12 ++++++------ test/test_prop.c | 12 ++++++------ 18 files changed, 77 insertions(+), 77 deletions(-) diff --git a/device.c b/device.c index e5f0915..fcbfbed 100644 --- a/device.c +++ b/device.c @@ -35,16 +35,15 @@ liftoff_device_create(int drm_fd) return NULL; } - device->crtcs = malloc(drm_res->count_crtcs * sizeof(uint32_t)); + device->crtcs_len = (size_t)drm_res->count_crtcs; + device->crtcs = malloc(device->crtcs_len * sizeof(device->crtcs[0])); if (device->crtcs == NULL) { liftoff_log_errno(LIFTOFF_ERROR, "malloc"); drmModeFreeResources(drm_res); liftoff_device_destroy(device); return NULL; } - device->crtcs_len = drm_res->count_crtcs; - memcpy(device->crtcs, drm_res->crtcs, - drm_res->count_crtcs * sizeof(uint32_t)); + memcpy(device->crtcs, drm_res->crtcs, device->crtcs_len * sizeof(device->crtcs[0])); drmModeFreeResources(drm_res); @@ -107,7 +106,7 @@ device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req, device->test_commit_counter++; - flags &= ~DRM_MODE_PAGE_FLIP_EVENT; + flags &= ~(uint32_t)DRM_MODE_PAGE_FLIP_EVENT; do { ret = drmModeAtomicCommit(device->drm_fd, req, DRM_MODE_ATOMIC_TEST_ONLY | flags, diff --git a/example/common.c b/example/common.c index edface8..0613217 100644 --- a/example/common.c +++ b/example/common.c @@ -134,7 +134,7 @@ dumb_fb_map(struct dumb_fb *fb, int drm_fd) } return mmap(0, fb->size, PROT_READ | PROT_WRITE, MAP_SHARED, drm_fd, - map.offset); + (off_t)map.offset); } void diff --git a/example/compositor.c b/example/compositor.c index e04c969..a2d0d1c 100644 --- a/example/compositor.c +++ b/example/compositor.c @@ -26,8 +26,8 @@ static const uint32_t colors[] = { }; static struct liftoff_layer * -add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width, - int height, bool with_alpha, bool white, struct dumb_fb *fb) +add_layer(int drm_fd, struct liftoff_output *output, int x, int y, uint32_t width, + uint32_t height, bool with_alpha, bool white, struct dumb_fb *fb) { static size_t color_idx = 0; uint32_t color; @@ -51,8 +51,8 @@ add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width, layer = liftoff_layer_create(output); liftoff_layer_set_property(layer, "FB_ID", fb->id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); liftoff_layer_set_property(layer, "CRTC_W", width); liftoff_layer_set_property(layer, "CRTC_H", height); liftoff_layer_set_property(layer, "SRC_X", 0); @@ -74,12 +74,12 @@ composite(int drm_fd, struct dumb_fb *dst_fb, struct dumb_fb *src_fb, int dst_x, dst = dumb_fb_map(dst_fb, drm_fd); src = dumb_fb_map(src_fb, drm_fd); - src_width = src_fb->width; + src_width = (int)src_fb->width; if (dst_x < 0) { dst_x = 0; } if (dst_x + src_width > (int)dst_fb->width) { - src_width = dst_fb->width - dst_x; + src_width = (int)dst_fb->width - dst_x; } for (i = 0; i < (int)src_fb->height; i++) { @@ -87,10 +87,10 @@ composite(int drm_fd, struct dumb_fb *dst_fb, struct dumb_fb *src_fb, int dst_x, if (y < 0 || y >= (int)dst_fb->height) { continue; } - memcpy(dst + dst_fb->stride * y + - dst_x * sizeof(uint32_t), - src + src_fb->stride * i, - src_width * sizeof(uint32_t)); + memcpy(dst + dst_fb->stride * (size_t)y + + (size_t)dst_x * sizeof(uint32_t), + src + src_fb->stride * (size_t)i, + (size_t)src_width * sizeof(uint32_t)); } munmap(dst, dst_fb->size); @@ -122,7 +122,7 @@ main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "l:h")) != -1) { switch (opt) { case 'l': - layers_len = atoi(optarg); + layers_len = (size_t)atoi(optarg); break; default: fprintf(stderr, diff --git a/example/dynamic.c b/example/dynamic.c index fbd15d0..7cf7543 100644 --- a/example/dynamic.c +++ b/example/dynamic.c @@ -35,7 +35,7 @@ static size_t active_layer_idx = 2; static bool init_layer(int drm_fd, struct example_layer *layer, - struct liftoff_output *output, int width, int height, + struct liftoff_output *output, uint32_t width, uint32_t height, bool with_alpha) { static size_t color_idx = 0; @@ -83,8 +83,8 @@ draw_layer(int drm_fd, struct example_layer *layer) dumb_fb_fill(fb, drm_fd, color); liftoff_layer_set_property(layer->layer, "FB_ID", fb->id); - liftoff_layer_set_property(layer->layer, "CRTC_X", layer->x); - liftoff_layer_set_property(layer->layer, "CRTC_Y", layer->y); + liftoff_layer_set_property(layer->layer, "CRTC_X", (uint64_t)layer->x); + liftoff_layer_set_property(layer->layer, "CRTC_Y", (uint64_t)layer->y); } static bool diff --git a/example/multi-output.c b/example/multi-output.c index cf86479..4bf7ea0 100644 --- a/example/multi-output.c +++ b/example/multi-output.c @@ -25,8 +25,8 @@ static const uint32_t colors[] = { }; static struct liftoff_layer * -add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width, - int height, bool with_alpha) +add_layer(int drm_fd, struct liftoff_output *output, int x, int y, uint32_t width, + uint32_t height, bool with_alpha) { static bool first = true; static size_t color_idx = 0; @@ -53,8 +53,8 @@ add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width, layer = liftoff_layer_create(output); liftoff_layer_set_property(layer, "FB_ID", fb.id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); liftoff_layer_set_property(layer, "CRTC_W", width); liftoff_layer_set_property(layer, "CRTC_H", height); liftoff_layer_set_property(layer, "SRC_X", 0); diff --git a/example/simple.c b/example/simple.c index 54adf68..e18a6b8 100644 --- a/example/simple.c +++ b/example/simple.c @@ -23,8 +23,8 @@ static const uint32_t colors[] = { }; static struct liftoff_layer * -add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width, - int height, bool with_alpha) +add_layer(int drm_fd, struct liftoff_output *output, int x, int y, uint32_t width, + uint32_t height, bool with_alpha) { static bool first = true; static size_t color_idx = 0; @@ -51,8 +51,8 @@ add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width, layer = liftoff_layer_create(output); liftoff_layer_set_property(layer, "FB_ID", fb.id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); liftoff_layer_set_property(layer, "CRTC_W", width); liftoff_layer_set_property(layer, "CRTC_H", height); liftoff_layer_set_property(layer, "SRC_X", 0); diff --git a/layer.c b/layer.c index 9aae93b..73a8186 100644 --- a/layer.c +++ b/layer.c @@ -334,7 +334,7 @@ layer_add_candidate_plane(struct liftoff_layer *layer, return; } if (empty_slot < 0 && layer->candidate_planes[i] == 0) { - empty_slot = i; + empty_slot = (ssize_t)i; } } diff --git a/meson.build b/meson.build index 79674ba..f6f0554 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,7 @@ add_project_arguments(cc.get_supported_arguments([ '-Walloca', '-Wdeclaration-after-statement', '-Wfloat-conversion', + '-Wsign-conversion', '-Wno-missing-braces', '-Wno-unused-parameter', diff --git a/output.c b/output.c index 32e6a1a..2acbd61 100644 --- a/output.c +++ b/output.c @@ -15,7 +15,7 @@ liftoff_output_create(struct liftoff_device *device, uint32_t crtc_id) crtc_index = -1; for (i = 0; i < device->crtcs_len; i++) { if (device->crtcs[i] == crtc_id) { - crtc_index = i; + crtc_index = (ssize_t)i; break; } } @@ -29,7 +29,7 @@ liftoff_output_create(struct liftoff_device *device, uint32_t crtc_id) } output->device = device; output->crtc_id = crtc_id; - output->crtc_index = crtc_index; + output->crtc_index = (size_t)crtc_index; liftoff_list_init(&output->layers); liftoff_list_insert(&device->outputs, &output->link); return output; diff --git a/plane.c b/plane.c index 6b9daa0..df7ec18 100644 --- a/plane.c +++ b/plane.c @@ -211,7 +211,7 @@ check_bitmask_prop(const drmModePropertyRes *prop, uint64_t value) mask = 0; for (i = 0; i < prop->count_enums; i++) { - mask |= 1 << prop->enums[i].value; + mask |= (uint64_t)1 << prop->enums[i].value; } if ((value & ~mask) != 0) { @@ -311,7 +311,7 @@ plane_check_layer_fb(struct liftoff_plane *plane, struct liftoff_layer *layer) format_index = -1; for (i = 0; i < set->count_formats; ++i) { if (formats[i] == layer->fb_info.pixel_format) { - format_index = i; + format_index = (ssize_t)i; break; } } @@ -323,7 +323,7 @@ plane_check_layer_fb(struct liftoff_plane *plane, struct liftoff_layer *layer) modifier_index = -1; for (i = 0; i < set->count_modifiers; i++) { if (modifiers[i].modifier == layer->fb_info.modifier) { - modifier_index = i; + modifier_index = (ssize_t)i; break; } } diff --git a/test/bench.c b/test/bench.c index a86e64b..95a5142 100644 --- a/test/bench.c +++ b/test/bench.c @@ -20,14 +20,14 @@ add_layer(struct liftoff_output *output, int x, int y, int width, int height) layer = liftoff_layer_create(output); fb_id = liftoff_mock_drm_create_fb(layer); liftoff_layer_set_property(layer, "FB_ID", fb_id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); - liftoff_layer_set_property(layer, "CRTC_W", width); - liftoff_layer_set_property(layer, "CRTC_H", height); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); + liftoff_layer_set_property(layer, "CRTC_W", (uint64_t)width); + liftoff_layer_set_property(layer, "CRTC_H", (uint64_t)height); liftoff_layer_set_property(layer, "SRC_X", 0); liftoff_layer_set_property(layer, "SRC_Y", 0); - liftoff_layer_set_property(layer, "SRC_W", width << 16); - liftoff_layer_set_property(layer, "SRC_H", height << 16); + liftoff_layer_set_property(layer, "SRC_W", (uint64_t)width << 16); + liftoff_layer_set_property(layer, "SRC_H", (uint64_t)height << 16); return layer; } @@ -40,7 +40,7 @@ main(int argc, char *argv[]) struct timespec start, end; struct liftoff_mock_plane *mock_planes[MAX_PLANES]; size_t i, j; - int plane_type; + uint64_t plane_type; int drm_fd; struct liftoff_device *device; struct liftoff_output *output; @@ -54,10 +54,10 @@ main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "p:l:")) != -1) { switch (opt) { case 'p': - planes_len = atoi(optarg); + planes_len = (size_t)atoi(optarg); break; case 'l': - layers_len = atoi(optarg); + layers_len = (size_t)atoi(optarg); break; default: fprintf(stderr, "usage: %s [-p planes] [-l layers]\n", diff --git a/test/libdrm_mock.c b/test/libdrm_mock.c index 7750e09..b1c9668 100644 --- a/test/libdrm_mock.c +++ b/test/libdrm_mock.c @@ -149,7 +149,7 @@ liftoff_mock_drm_open(void) } struct liftoff_mock_plane * -liftoff_mock_drm_create_plane(int type) +liftoff_mock_drm_create_plane(uint64_t type) { struct liftoff_mock_plane *plane; size_t i; diff --git a/test/libdrm_mock.h b/test/libdrm_mock.h index 70e6d76..1457a63 100644 --- a/test/libdrm_mock.h +++ b/test/libdrm_mock.h @@ -27,7 +27,7 @@ void liftoff_mock_drm_set_fb_info(const drmModeFB2 *fb_info); struct liftoff_mock_plane * -liftoff_mock_drm_create_plane(int type); +liftoff_mock_drm_create_plane(uint64_t type); struct liftoff_mock_plane * liftoff_mock_drm_get_plane(uint32_t id); diff --git a/test/test_alloc.c b/test/test_alloc.c index 84eeae1..d786c47 100644 --- a/test/test_alloc.c +++ b/test/test_alloc.c @@ -15,20 +15,20 @@ add_layer(struct liftoff_output *output, int x, int y, int width, int height) layer = liftoff_layer_create(output); fb_id = liftoff_mock_drm_create_fb(layer); liftoff_layer_set_property(layer, "FB_ID", fb_id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); - liftoff_layer_set_property(layer, "CRTC_W", width); - liftoff_layer_set_property(layer, "CRTC_H", height); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); + liftoff_layer_set_property(layer, "CRTC_W", (uint64_t)width); + liftoff_layer_set_property(layer, "CRTC_H", (uint64_t)height); liftoff_layer_set_property(layer, "SRC_X", 0); liftoff_layer_set_property(layer, "SRC_Y", 0); - liftoff_layer_set_property(layer, "SRC_W", width << 16); - liftoff_layer_set_property(layer, "SRC_H", height << 16); + liftoff_layer_set_property(layer, "SRC_W", (uint64_t)width << 16); + liftoff_layer_set_property(layer, "SRC_H", (uint64_t)height << 16); return layer; } struct test_plane { - int type; + uint64_t type; }; struct test_prop { @@ -820,7 +820,7 @@ run_test(const struct test_case *test) plane_index_got = -1; for (j = 0; j < test_setup_len; j++) { if (mock_planes[j] == mock_plane) { - plane_index_got = j; + plane_index_got = (ssize_t)j; break; } } diff --git a/test/test_candidate.c b/test/test_candidate.c index a8dd977..b7697de 100644 --- a/test/test_candidate.c +++ b/test/test_candidate.c @@ -14,14 +14,14 @@ add_layer(struct liftoff_output *output, int x, int y, int width, int height) layer = liftoff_layer_create(output); fb_id = liftoff_mock_drm_create_fb(layer); liftoff_layer_set_property(layer, "FB_ID", fb_id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); - liftoff_layer_set_property(layer, "CRTC_W", width); - liftoff_layer_set_property(layer, "CRTC_H", height); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); + liftoff_layer_set_property(layer, "CRTC_W", (uint64_t)width); + liftoff_layer_set_property(layer, "CRTC_H", (uint64_t)height); liftoff_layer_set_property(layer, "SRC_X", 0); liftoff_layer_set_property(layer, "SRC_Y", 0); - liftoff_layer_set_property(layer, "SRC_W", width << 16); - liftoff_layer_set_property(layer, "SRC_H", height << 16); + liftoff_layer_set_property(layer, "SRC_W", (uint64_t)width << 16); + liftoff_layer_set_property(layer, "SRC_H", (uint64_t)height << 16); return layer; } diff --git a/test/test_dynamic.c b/test/test_dynamic.c index a483648..048783c 100644 --- a/test/test_dynamic.c +++ b/test/test_dynamic.c @@ -29,14 +29,14 @@ add_layer(struct liftoff_output *output, int x, int y, int width, int height) layer = liftoff_layer_create(output); fb_id = liftoff_mock_drm_create_fb(layer); liftoff_layer_set_property(layer, "FB_ID", fb_id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); - liftoff_layer_set_property(layer, "CRTC_W", width); - liftoff_layer_set_property(layer, "CRTC_H", height); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); + liftoff_layer_set_property(layer, "CRTC_W", (uint64_t)width); + liftoff_layer_set_property(layer, "CRTC_H", (uint64_t)height); liftoff_layer_set_property(layer, "SRC_X", 0); liftoff_layer_set_property(layer, "SRC_Y", 0); - liftoff_layer_set_property(layer, "SRC_W", width << 16); - liftoff_layer_set_property(layer, "SRC_H", height << 16); + liftoff_layer_set_property(layer, "SRC_W", (uint64_t)width << 16); + liftoff_layer_set_property(layer, "SRC_H", (uint64_t)height << 16); return layer; } diff --git a/test/test_priority.c b/test/test_priority.c index 1c24ec4..598dfcc 100644 --- a/test/test_priority.c +++ b/test/test_priority.c @@ -17,14 +17,14 @@ add_layer(struct liftoff_output *output, int x, int y, int width, int height) layer = liftoff_layer_create(output); fb_id = liftoff_mock_drm_create_fb(layer); liftoff_layer_set_property(layer, "FB_ID", fb_id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); - liftoff_layer_set_property(layer, "CRTC_W", width); - liftoff_layer_set_property(layer, "CRTC_H", height); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); + liftoff_layer_set_property(layer, "CRTC_W", (uint64_t)width); + liftoff_layer_set_property(layer, "CRTC_H", (uint64_t)height); liftoff_layer_set_property(layer, "SRC_X", 0); liftoff_layer_set_property(layer, "SRC_Y", 0); - liftoff_layer_set_property(layer, "SRC_W", width << 16); - liftoff_layer_set_property(layer, "SRC_H", height << 16); + liftoff_layer_set_property(layer, "SRC_W", (uint64_t)width << 16); + liftoff_layer_set_property(layer, "SRC_H", (uint64_t)height << 16); return layer; } diff --git a/test/test_prop.c b/test/test_prop.c index 044c455..de29030 100644 --- a/test/test_prop.c +++ b/test/test_prop.c @@ -15,14 +15,14 @@ add_layer(struct liftoff_output *output, int x, int y, int width, int height) layer = liftoff_layer_create(output); fb_id = liftoff_mock_drm_create_fb(layer); liftoff_layer_set_property(layer, "FB_ID", fb_id); - liftoff_layer_set_property(layer, "CRTC_X", x); - liftoff_layer_set_property(layer, "CRTC_Y", y); - liftoff_layer_set_property(layer, "CRTC_W", width); - liftoff_layer_set_property(layer, "CRTC_H", height); + liftoff_layer_set_property(layer, "CRTC_X", (uint64_t)x); + liftoff_layer_set_property(layer, "CRTC_Y", (uint64_t)y); + liftoff_layer_set_property(layer, "CRTC_W", (uint64_t)width); + liftoff_layer_set_property(layer, "CRTC_H", (uint64_t)height); liftoff_layer_set_property(layer, "SRC_X", 0); liftoff_layer_set_property(layer, "SRC_Y", 0); - liftoff_layer_set_property(layer, "SRC_W", width << 16); - liftoff_layer_set_property(layer, "SRC_H", height << 16); + liftoff_layer_set_property(layer, "SRC_W", (uint64_t)width << 16); + liftoff_layer_set_property(layer, "SRC_H", (uint64_t)height << 16); return layer; }