From 722f3eae42cab24f686be7cbcab3cb29e3da816a Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Sat, 20 Jul 2024 11:14:13 -0400 Subject: [PATCH] Fix build errors with -Werror and NDEBUG To reproduce: meson setup build -Db_ndebug=true --werror meson compile -C build --- backend/wayland/backend.c | 5 ++--- examples/pointer.c | 3 +-- render/pass.c | 4 ++-- types/output/render.c | 3 +-- types/wlr_compositor.c | 12 ++++++------ types/wlr_output_management_v1.c | 13 ++++++------- types/wlr_shm.c | 12 ++++++++---- xwayland/selection/dnd.c | 12 ++++-------- xwayland/xwm.c | 7 +++---- 9 files changed, 33 insertions(+), 38 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index c2b2f2faa..0ed0342d0 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -213,11 +213,10 @@ static void linux_dmabuf_feedback_v1_handle_tranche_formats(void *data, return; } - size_t table_cap = feedback_data->format_table_size / - sizeof(struct wlr_wl_linux_dmabuf_v1_table_entry); uint16_t *index_ptr; wl_array_for_each(index_ptr, indices_arr) { - assert(*index_ptr < table_cap); + assert(*index_ptr < feedback_data->format_table_size / + sizeof(struct wlr_wl_linux_dmabuf_v1_table_entry)); const struct wlr_wl_linux_dmabuf_v1_table_entry *entry = &feedback_data->format_table[*index_ptr]; wlr_drm_format_set_add(&feedback_data->backend->linux_dmabuf_v1_formats, diff --git a/examples/pointer.c b/examples/pointer.c index fed37a5b3..374340713 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -96,8 +96,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { struct sample_output *sample_output = wl_container_of(listener, sample_output, frame); struct sample_state *state = sample_output->state; struct wlr_output *wlr_output = sample_output->output; - struct wlr_renderer *renderer = state->renderer; - assert(renderer); + assert(state->renderer); struct wlr_output_state output_state; wlr_output_state_init(&output_state); diff --git a/render/pass.c b/render/pass.c index 902228273..12e234ffd 100644 --- a/render/pass.c +++ b/render/pass.c @@ -18,8 +18,8 @@ void wlr_render_pass_add_texture(struct wlr_render_pass *render_pass, const struct wlr_render_texture_options *options) { // make sure the texture source box does not try and sample outside of the // texture - if (!wlr_fbox_empty(&options->src_box)) { - const struct wlr_fbox *box = &options->src_box; + const struct wlr_fbox *box = &options->src_box; + if (!wlr_fbox_empty(box)) { assert(box->x >= 0 && box->y >= 0 && box->x + box->width <= options->texture->width && box->y + box->height <= options->texture->height); diff --git a/types/output/render.c b/types/output/render.c index 709646a10..364642a41 100644 --- a/types/output/render.c +++ b/types/output/render.c @@ -152,8 +152,7 @@ bool output_pick_format(struct wlr_output *output, const struct wlr_drm_format_set *display_formats, struct wlr_drm_format *format, uint32_t fmt) { struct wlr_renderer *renderer = output->renderer; - struct wlr_allocator *allocator = output->allocator; - assert(renderer != NULL && allocator != NULL); + assert(renderer != NULL && output->allocator != NULL); const struct wlr_drm_format_set *render_formats = wlr_renderer_get_render_formats(renderer); diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index c5044ce44..a68585314 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -935,15 +935,14 @@ void wlr_surface_unlock_cached(struct wlr_surface *surface, uint32_t seq) { return; } - bool found = false; - struct wlr_surface_state *cached; - wl_list_for_each(cached, &surface->cached, cached_state_link) { - if (cached->seq == seq) { - found = true; + struct wlr_surface_state *cached = NULL, *iter; + wl_list_for_each(iter, &surface->cached, cached_state_link) { + if (iter->seq == seq) { + cached = iter; break; } } - assert(found); + assert(cached); assert(cached->cached_state_locks > 0); cached->cached_state_locks--; @@ -1485,6 +1484,7 @@ void wlr_surface_synced_finish(struct wlr_surface_synced *synced) { } } assert(found); + (void)found; struct wlr_surface_state *cached; wl_list_for_each(cached, &surface->cached, cached_state_link) { diff --git a/types/wlr_output_management_v1.c b/types/wlr_output_management_v1.c index ecc32dede..f93fb7928 100644 --- a/types/wlr_output_management_v1.c +++ b/types/wlr_output_management_v1.c @@ -760,16 +760,15 @@ static void head_send_state(struct wlr_output_head_v1 *head, } if (state & HEAD_STATE_MODE) { - bool found = false; - struct wl_resource *mode_resource; - wl_resource_for_each(mode_resource, &head->mode_resources) { - if (wl_resource_get_client(mode_resource) == client && - mode_from_resource(mode_resource) == head->state.mode) { - found = true; + struct wl_resource *mode_resource = NULL, *iter; + wl_resource_for_each(iter, &head->mode_resources) { + if (wl_resource_get_client(iter) == client && + mode_from_resource(iter) == head->state.mode) { + mode_resource = iter; break; } } - assert(found); + assert(mode_resource); if (head->state.mode == NULL) { // Fake a single output mode if output doesn't support modes diff --git a/types/wlr_shm.c b/types/wlr_shm.c index 1f45c88a3..cf6a08f5f 100644 --- a/types/wlr_shm.c +++ b/types/wlr_shm.c @@ -495,10 +495,8 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) { free(shm); } -struct wlr_shm *wlr_shm_create(struct wl_display *display, uint32_t version, +static bool __attribute__((unused)) has_argb8888_and_xrgb8888( const uint32_t *formats, size_t formats_len) { - assert(version <= SHM_VERSION); - // ARGB8888 and XRGB8888 must be supported per the wl_shm spec bool has_argb8888 = false, has_xrgb8888 = false; for (size_t i = 0; i < formats_len; i++) { @@ -511,7 +509,13 @@ struct wlr_shm *wlr_shm_create(struct wl_display *display, uint32_t version, break; } } - assert(has_argb8888 && has_xrgb8888); + return has_argb8888 && has_xrgb8888; +} + +struct wlr_shm *wlr_shm_create(struct wl_display *display, uint32_t version, + const uint32_t *formats, size_t formats_len) { + assert(version <= SHM_VERSION); + assert(has_argb8888_and_xrgb8888(formats, formats_len)); struct wlr_shm *shm = calloc(1, sizeof(*shm)); if (shm == NULL) { diff --git a/xwayland/selection/dnd.c b/xwayland/selection/dnd.c index e9cc63d9b..11c66be9f 100644 --- a/xwayland/selection/dnd.c +++ b/xwayland/selection/dnd.c @@ -120,10 +120,8 @@ static void xwm_dnd_send_position(struct wlr_xwm *xwm, uint32_t time, int16_t x, } static void xwm_dnd_send_drop(struct wlr_xwm *xwm, uint32_t time) { - struct wlr_drag *drag = xwm->drag; - assert(drag != NULL); - struct wlr_xwayland_surface *dest = xwm->drag_focus; - assert(dest != NULL); + assert(xwm->drag != NULL); + assert(xwm->drag_focus != NULL); xcb_client_message_data_t data = { 0 }; data.data32[0] = xwm->dnd_selection.window; @@ -133,10 +131,8 @@ static void xwm_dnd_send_drop(struct wlr_xwm *xwm, uint32_t time) { } static void xwm_dnd_send_leave(struct wlr_xwm *xwm) { - struct wlr_drag *drag = xwm->drag; - assert(drag != NULL); - struct wlr_xwayland_surface *dest = xwm->drag_focus; - assert(dest != NULL); + assert(xwm->drag != NULL); + assert(xwm->drag_focus != NULL); xcb_client_message_data_t data = { 0 }; data.data32[0] = xwm->dnd_selection.window; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index c65851bb8..9a6f906f9 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -264,15 +264,14 @@ xcb_void_cookie_t xwm_send_event_with_size(xcb_connection_t *c, uint8_t propagate, xcb_window_t destination, uint32_t event_mask, const void *event, uint32_t length) { - if (length == 32) { + assert(length <= 32); + if (length >= 32) { return xcb_send_event(c, propagate, destination, event_mask, event); - } else if (length < 32) { + } else { char buf[32]; memcpy(buf, event, length); memset(buf + length, 0, 32 - length); return xcb_send_event(c, propagate, destination, event_mask, buf); - } else { - assert(false && "Event too long"); } }