From 1ec56844387ed910b7e87bae186b58cc22cc317a Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Tue, 9 Feb 2021 13:52:33 +0000 Subject: [PATCH 1/4] Convert some uses of xassert(false) to BUG("some error message") --- config.c | 2 +- fdm.c | 2 +- input.c | 2 +- render.c | 5 ++--- terminal.c | 11 +++++------ 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/config.c b/config.c index 04d563eb..56acb0cf 100644 --- a/config.c +++ b/config.c @@ -1230,7 +1230,7 @@ argv_compare(char *const *argv1, char *const *argv2) return ret; } - xassert(false); + BUG("unexpected loop break"); return 1; } diff --git a/fdm.c b/fdm.c index 3394f10c..ef956450 100644 --- a/fdm.c +++ b/fdm.c @@ -251,7 +251,7 @@ hook_priority_to_list(struct fdm *fdm, enum fdm_hook_priority priority) case FDM_HOOK_PRIORITY_HIGH: return &fdm->hooks_high; } - xassert(false); + BUG("unhandled priority type"); return NULL; } diff --git a/input.c b/input.c index 79368270..ad3934b6 100644 --- a/input.c +++ b/input.c @@ -209,7 +209,7 @@ execute_binding(struct seat *seat, struct terminal *term, break; default: - xassert(false); + BUG("Unhandled action type"); success = false; break; } diff --git a/render.c b/render.c index 71d54f4c..99869c2c 100644 --- a/render.c +++ b/render.c @@ -1367,11 +1367,10 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx) case CSD_SURF_CLOSE: return (struct csd_data){term->width - 1 * button_width, 0, button_close_width, title_height}; case CSD_SURF_COUNT: - xassert(false); - return (struct csd_data){0}; + break; } - xassert(false); + BUG("Invalid csd_surface type"); return (struct csd_data){0}; } diff --git a/terminal.c b/terminal.c index 8e1e1841..c080c0c4 100644 --- a/terminal.c +++ b/terminal.c @@ -97,8 +97,7 @@ data_to_slave(struct terminal *term, const void *data, size_t len, return false; } - /* Shouldn't get here */ - xassert(false); + BUG("Unexpected async_write() return value"); return false; } @@ -1931,7 +1930,7 @@ term_row_rel_to_abs(const struct terminal *term, int row) return min(row + term->scroll_region.start, term->scroll_region.end - 1); } - xassert(false); + BUG("Invalid cursor_origin value"); return -1; } @@ -2483,7 +2482,7 @@ term_mouse_down(struct terminal *term, int button, int row, int col, case MOUSE_X10: /* Never enabled */ - xassert(false && "unimplemented"); + BUG("X10 mouse mode not implemented"); break; } } @@ -2525,7 +2524,7 @@ term_mouse_up(struct terminal *term, int button, int row, int col, case MOUSE_X10: /* Never enabled */ - xassert(false && "unimplemented"); + BUG("X10 mouse mode not implemented"); break; } } @@ -2572,7 +2571,7 @@ term_mouse_motion(struct terminal *term, int button, int row, int col, case MOUSE_X10: /* Never enabled */ - xassert(false && "unimplemented"); + BUG("X10 mouse mode not implemented"); break; } } From 2f81a1d07c3828391bf1b5656a9143aaf3822089 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Tue, 9 Feb 2021 15:16:19 +0000 Subject: [PATCH 2/4] Convert some more uses of xassert(false) to BUG("...") --- input.c | 4 ++-- render.c | 2 +- search.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/input.c b/input.c index ad3934b6..944f1336 100644 --- a/input.c +++ b/input.c @@ -325,7 +325,7 @@ execute_binding(struct seat *seat, struct terminal *term, return true; case BIND_ACTION_COUNT: - xassert(false); + BUG("Invalid action type"); return false; } @@ -1150,7 +1150,7 @@ xcursor_for_csd_border(struct terminal *term, int x, int y) else if (term->active_surface == TERM_SURF_BORDER_TOP) return XCURSOR_TOP_SIDE; else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) return XCURSOR_BOTTOM_SIDE; else { - xassert(false); + BUG("Unreachable"); return NULL; } } diff --git a/render.c b/render.c index 99869c2c..8cf7f29a 100644 --- a/render.c +++ b/render.c @@ -1669,7 +1669,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) break; default: - xassert(false); + BUG("unhandled surface type: %u", (unsigned)surf_idx); break; } diff --git a/search.c b/search.c index 4fde8a92..d7939219 100644 --- a/search.c +++ b/search.c @@ -785,11 +785,11 @@ execute_binding(struct seat *seat, struct terminal *term, return true; case BIND_ACTION_SEARCH_COUNT: - xassert(false); + BUG("Invalid action type"); return true; } - xassert(false); + BUG("Unhandled action type"); return false; } From 3c86af52c2a3e9352a88e969392575e55c3b6f74 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Wed, 10 Feb 2021 09:01:51 +0000 Subject: [PATCH 3/4] Convert all but 2 remaining uses of xassert(false) to BUG("...") --- fdm.c | 8 ++------ input.c | 4 ++-- render.c | 4 ++-- selection.c | 13 ++++++------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/fdm.c b/fdm.c index ef956450..34d0fbff 100644 --- a/fdm.c +++ b/fdm.c @@ -105,16 +105,12 @@ fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data) #if defined(_DEBUG) int flags = fcntl(fd, F_GETFL); if (!(flags & O_NONBLOCK)) { - LOG_ERR("FD=%d is in blocking mode", fd); - xassert(false); - return false; + BUG("FD=%d is in blocking mode", fd); } tll_foreach(fdm->fds, it) { if (it->item->fd == fd) { - LOG_ERR("FD=%d already registered", fd); - xassert(false); - return false; + BUG("FD=%d already registered", fd); } } #endif diff --git a/input.c b/input.c index 944f1336..64ab2065 100644 --- a/input.c +++ b/input.c @@ -1225,7 +1225,7 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_NONE: - xassert(false); + BUG("Invalid surface type"); break; } } @@ -1806,7 +1806,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } case TERM_SURF_NONE: - xassert(false); + BUG("Invalid surface type"); break; } diff --git a/render.c b/render.c index 8cf7f29a..026f176f 100644 --- a/render.c +++ b/render.c @@ -1642,7 +1642,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx) break; default: - xassert(false); + BUG("unhandled surface type: %u", (unsigned)surf_idx); break; } @@ -1878,7 +1878,7 @@ render_scrollback_position(struct terminal *term) int surf_top = 0; switch (term->conf->scrollback.indicator.position) { case SCROLLBACK_INDICATOR_POSITION_NONE: - xassert(false); + BUG("Invalid scrollback indicator position type"); return; case SCROLLBACK_INDICATOR_POSITION_FIXED: diff --git a/selection.c b/selection.c index 90c6c392..cb625541 100644 --- a/selection.c +++ b/selection.c @@ -195,11 +195,10 @@ foreach_selected( return; case SELECTION_NONE: - xassert(false); - return; + break; } - xassert(false); + BUG("Invalid selection kind"); } static bool @@ -426,7 +425,7 @@ selection_start(struct terminal *term, int col, int row, break; case SELECTION_NONE: - xassert(false); + BUG("Invalid selection kind"); break; } @@ -728,7 +727,7 @@ selection_update(struct terminal *term, int col, int row) break; case SELECTION_NONE: - xassert(false); + BUG("Invalid selection kind"); break; } @@ -861,7 +860,7 @@ selection_extend_normal(struct terminal *term, int col, int row, case SELECTION_BLOCK: case SELECTION_NONE: - xassert(false); + BUG("Invalid selection kind in this context"); break; } @@ -963,7 +962,7 @@ selection_extend(struct seat *seat, struct terminal *term, switch (term->selection.kind) { case SELECTION_NONE: - xassert(false); + BUG("Invalid selection kind"); return; case SELECTION_CHAR_WISE: From 19a5f25b80f44e5440a444df8af443d0081e46bf Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Wed, 10 Feb 2021 09:18:50 +0000 Subject: [PATCH 4/4] Mark slave_exec() as "noreturn" and convert xassert(false) to BUG(...) --- slave.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/slave.c b/slave.c index 29ad92f5..432e21ff 100644 --- a/slave.c +++ b/slave.c @@ -18,6 +18,7 @@ #include "log.h" #include "debug.h" +#include "macros.h" #include "terminal.h" #include "tokenize.h" #include "xmalloc.h" @@ -143,7 +144,7 @@ emit_notifications(int fd, const user_notifications_t *notifications) emit_notifications_of_kind(fd, notifications, USER_NOTIFICATION_DEPRECATED); } -static void +static noreturn void slave_exec(int ptmx, char *argv[], int err_fd, bool login_shell, const user_notifications_t *notifications) { @@ -316,7 +317,7 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv, setenv("SHELL", shell_argv[0], 1); slave_exec(ptmx, shell_argv, fork_pipe[1], login_shell, notifications); - xassert(false); + BUG("Unexpected return from slave_exec()"); break; default: {