Turn on -Wsign-conversion

References: https://gitlab.freedesktop.org/emersion/libliftoff/-/issues/74
This commit is contained in:
Simon Ser 2023-02-16 21:33:36 +01:00
parent b2721f739c
commit ce325b1ee6
18 changed files with 77 additions and 77 deletions

View file

@ -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,

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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',

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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",

View file

@ -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;

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}