debug: rename assert() to xassert(), to avoid clashing with <assert.h>

This commit is contained in:
Craig Barnes 2021-01-16 20:16:00 +00:00
parent 22f25a9e4f
commit e56136ce11
31 changed files with 387 additions and 388 deletions

View file

@ -98,7 +98,7 @@ invalid:
char * char *
base64_encode(const uint8_t *data, size_t size) base64_encode(const uint8_t *data, size_t size)
{ {
assert(size % 3 == 0); xassert(size % 3 == 0);
if (unlikely(size % 3 != 0)) if (unlikely(size % 3 != 0))
return NULL; return NULL;
@ -138,8 +138,8 @@ base64_encode(const uint8_t *data, size_t size)
void void
base64_encode_final(const uint8_t *data, size_t size, char result[4]) base64_encode_final(const uint8_t *data, size_t size, char result[4])
{ {
assert(size > 0); xassert(size > 0);
assert(size < 3); xassert(size < 3);
uint32_t v = 0; uint32_t v = 0;
if (size >= 1) if (size >= 1)

View file

@ -170,7 +170,7 @@ draw_box_drawings_dash_horizontal(struct buf *buf, int count, int thick, int gap
int width = buf->width; int width = buf->width;
int height = buf->height; int height = buf->height;
assert(count >= 2 && count <= 4); xassert(count >= 2 && count <= 4);
const int gap_count = count - 1; const int gap_count = count - 1;
int dash_width = (width - (gap_count * gap)) / count; int dash_width = (width - (gap_count * gap)) / count;
@ -184,7 +184,7 @@ draw_box_drawings_dash_horizontal(struct buf *buf, int count, int thick, int gap
return; return;
} }
assert(count * dash_width + gap_count * gap <= width); xassert(count * dash_width + gap_count * gap <= width);
int remaining = width - count * dash_width - gap_count * gap; int remaining = width - count * dash_width - gap_count * gap;
@ -228,7 +228,7 @@ draw_box_drawings_dash_vertical(struct buf *buf, int count, int thick, int gap)
int width = buf->width; int width = buf->width;
int height = buf->height; int height = buf->height;
assert(count >= 2 && count <= 4); xassert(count >= 2 && count <= 4);
const int gap_count = count - 1; const int gap_count = count - 1;
int dash_height = (height - (gap_count * gap)) / count; int dash_height = (height - (gap_count * gap)) / count;
@ -242,7 +242,7 @@ draw_box_drawings_dash_vertical(struct buf *buf, int count, int thick, int gap)
return; return;
} }
assert(count * dash_height + gap_count * gap <= height); xassert(count * dash_height + gap_count * gap <= height);
int remaining = height - count * dash_height - gap_count * gap; int remaining = height - count * dash_height - gap_count * gap;
@ -1304,8 +1304,8 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf)
break; break;
} }
assert(row_end > row_start); xassert(row_end > row_start);
assert(col_end > col_start); xassert(col_end > col_start);
for (int r = max(row_start, 0); r < max(min(row_end, buf->height), 0); r++) { for (int r = max(row_start, 0); r < max(min(row_end, buf->height), 0); r++) {
for (int c = max(col_start, 0); c < max(min(col_end, buf->width), 0); c++) { for (int c = max(col_start, 0); c < max(min(col_end, buf->width), 0); c++) {
@ -1844,10 +1844,10 @@ draw_sextant(wchar_t wc, struct buf *buf)
UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT, UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT,
}; };
assert(wc >= 0x1fb00 && wc <= 0x1fb3b); xassert(wc >= 0x1fb00 && wc <= 0x1fb3b);
const size_t idx = wc - 0x1fb00; const size_t idx = wc - 0x1fb00;
assert(idx < ALEN(matrix)); xassert(idx < ALEN(matrix));
uint8_t encoded = matrix[idx]; uint8_t encoded = matrix[idx];
if (encoded & UPPER_LEFT) if (encoded & UPPER_LEFT)

View file

@ -329,7 +329,7 @@ main(int argc, char *const *argv)
ssize_t rcvd = recv(fd, &exit_code, sizeof(exit_code), 0); ssize_t rcvd = recv(fd, &exit_code, sizeof(exit_code), 0);
if (rcvd == -1 && errno == EINTR) if (rcvd == -1 && errno == EINTR)
assert(aborted); xassert(aborted);
else if (rcvd != sizeof(exit_code)) else if (rcvd != sizeof(exit_code))
LOG_ERRNO("failed to read server response"); LOG_ERRNO("failed to read server response");
else else

View file

@ -19,15 +19,15 @@ cmd_scrollback_up(struct terminal *term, int rows)
return; return;
rows = min(rows, term->rows); rows = min(rows, term->rows);
assert(term->grid->offset >= 0); xassert(term->grid->offset >= 0);
int new_view = term->grid->view - rows; int new_view = term->grid->view - rows;
while (new_view < 0) while (new_view < 0)
new_view += term->grid->num_rows; new_view += term->grid->num_rows;
new_view %= term->grid->num_rows; new_view %= term->grid->num_rows;
assert(new_view >= 0); xassert(new_view >= 0);
assert(new_view < term->grid->num_rows); xassert(new_view < term->grid->num_rows);
/* Avoid scrolling in uninitialized rows */ /* Avoid scrolling in uninitialized rows */
while (term->grid->rows[new_view] == NULL) while (term->grid->rows[new_view] == NULL)
@ -59,7 +59,7 @@ cmd_scrollback_up(struct terminal *term, int rows)
#if defined(_DEBUG) #if defined(_DEBUG)
for (int r = 0; r < term->rows; r++) for (int r = 0; r < term->rows; r++)
assert(term->grid->rows[(new_view + r) % term->grid->num_rows] != NULL); xassert(term->grid->rows[(new_view + r) % term->grid->num_rows] != NULL);
#endif #endif
LOG_DBG("scrollback UP: %d -> %d (offset = %d, end = %d, rows = %d)", LOG_DBG("scrollback UP: %d -> %d (offset = %d, end = %d, rows = %d)",
@ -99,11 +99,11 @@ cmd_scrollback_down(struct terminal *term, int rows)
return; return;
rows = min(rows, term->rows); rows = min(rows, term->rows);
assert(term->grid->offset >= 0); xassert(term->grid->offset >= 0);
int new_view = (term->grid->view + rows) % term->grid->num_rows; int new_view = (term->grid->view + rows) % term->grid->num_rows;
assert(new_view >= 0); xassert(new_view >= 0);
assert(new_view < term->grid->num_rows); xassert(new_view < term->grid->num_rows);
/* Prevent scrolling in uninitialized rows */ /* Prevent scrolling in uninitialized rows */
bool all_initialized = false; bool all_initialized = false;
@ -133,7 +133,7 @@ cmd_scrollback_down(struct terminal *term, int rows)
#if defined(_DEBUG) #if defined(_DEBUG)
for (int r = 0; r < term->rows; r++) for (int r = 0; r < term->rows; r++)
assert(term->grid->rows[(new_view + r) % term->grid->num_rows] != NULL); xassert(term->grid->rows[(new_view + r) % term->grid->num_rows] != NULL);
#endif #endif
LOG_DBG("scrollback DOWN: %d -> %d (offset = %d, end = %d, rows = %d)", LOG_DBG("scrollback DOWN: %d -> %d (offset = %d, end = %d, rows = %d)",

View file

@ -184,8 +184,8 @@ typedef tll(struct path_component) path_components_t;
static void static void
path_component_add(path_components_t *components, const char *comp, int fd) path_component_add(path_components_t *components, const char *comp, int fd)
{ {
assert(comp != NULL); xassert(comp != NULL);
assert(fd >= 0); xassert(fd >= 0);
struct path_component pc = {.component = comp, .fd = fd}; struct path_component pc = {.component = comp, .fd = fd};
tll_push_back(*components, pc); tll_push_back(*components, pc);
@ -194,7 +194,7 @@ path_component_add(path_components_t *components, const char *comp, int fd)
static void static void
path_component_destroy(struct path_component *component) path_component_destroy(struct path_component *component)
{ {
assert(component->fd >= 0); xassert(component->fd >= 0);
close(component->fd); close(component->fd);
} }
@ -332,7 +332,7 @@ open_config(struct config *conf)
continue; continue;
} }
assert(tll_length(components) == 0); xassert(tll_length(components) == 0);
path_component_add(&components, xdg_dir, xdg_fd); path_component_add(&components, xdg_dir, xdg_fd);
path_component_add(&components, "foot", foot_fd); path_component_add(&components, "foot", foot_fd);
@ -347,7 +347,7 @@ out:
return ret; return ret;
done: done:
assert(tll_length(components) > 0); xassert(tll_length(components) > 0);
ret = path_components_to_config_file(&components); ret = path_components_to_config_file(&components);
goto out; goto out;
} }
@ -1023,7 +1023,7 @@ static bool
parse_key_combos(struct config *conf, const char *combos, key_combo_list_t *key_combos, parse_key_combos(struct config *conf, const char *combos, key_combo_list_t *key_combos,
const char *path, unsigned lineno) const char *path, unsigned lineno)
{ {
assert(tll_length(*key_combos) == 0); xassert(tll_length(*key_combos) == 0);
char *copy = xstrdup(combos); char *copy = xstrdup(combos);
@ -1136,8 +1136,8 @@ has_search_binding_collisions(struct config *conf, enum bind_action_search actio
static int static int
argv_compare(char *const *argv1, char *const *argv2) argv_compare(char *const *argv1, char *const *argv2)
{ {
assert(argv1 != NULL); xassert(argv1 != NULL);
assert(argv2 != NULL); xassert(argv2 != NULL);
for (size_t i = 0; ; i++) { for (size_t i = 0; ; i++) {
if (argv1[i] == NULL && argv2[i] == NULL) if (argv1[i] == NULL && argv2[i] == NULL)
@ -1152,7 +1152,7 @@ argv_compare(char *const *argv1, char *const *argv2)
return ret; return ret;
} }
assert(false); xassert(false);
return 1; return 1;
} }
@ -1372,7 +1372,7 @@ static bool
parse_mouse_combos(struct config *conf, const char *combos, key_combo_list_t *key_combos, parse_mouse_combos(struct config *conf, const char *combos, key_combo_list_t *key_combos,
const char *path, unsigned lineno) const char *path, unsigned lineno)
{ {
assert(tll_length(*key_combos) == 0); xassert(tll_length(*key_combos) == 0);
char *copy = xstrdup(combos); char *copy = xstrdup(combos);
@ -1874,7 +1874,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar
/* Strip trailing whitespace from key (leading stripped earlier) */ /* Strip trailing whitespace from key (leading stripped earlier) */
{ {
assert(!isspace(*key)); xassert(!isspace(*key));
char *end = key + strlen(key) - 1; char *end = key + strlen(key) - 1;
while (isspace(*end)) while (isspace(*end))
@ -1898,10 +1898,10 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar
LOG_DBG("section=%s, key='%s', value='%s', comment='%s'", LOG_DBG("section=%s, key='%s', value='%s', comment='%s'",
section_info[section].name, key, value, comment); section_info[section].name, key, value, comment);
assert(section >= 0 && section < SECTION_COUNT); xassert(section >= 0 && section < SECTION_COUNT);
parser_fun_t section_parser = section_info[section].fun; parser_fun_t section_parser = section_info[section].fun;
assert(section_parser != NULL); xassert(section_parser != NULL);
if (!section_parser(key, value, conf, path, lineno)) if (!section_parser(key, value, conf, path, lineno))
error_or_continue(); error_or_continue();
@ -2176,8 +2176,8 @@ config_load(struct config *conf, const char *conf_path,
} }
} }
assert(conf_file.path != NULL); xassert(conf_file.path != NULL);
assert(conf_file.fd >= 0); xassert(conf_file.fd >= 0);
LOG_INFO("loading configuration from %s", conf_file.path); LOG_INFO("loading configuration from %s", conf_file.path);
FILE *f = fdopen(conf_file.fd, "r"); FILE *f = fdopen(conf_file.fd, "r");

4
csi.c
View file

@ -1083,7 +1083,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
break; break;
} }
} }
assert(new_col >= term->grid->cursor.point.col); xassert(new_col >= term->grid->cursor.point.col);
term_cursor_right(term, new_col - term->grid->cursor.point.col); term_cursor_right(term, new_col - term->grid->cursor.point.col);
} }
break; break;
@ -1099,7 +1099,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
break; break;
} }
} }
assert(term->grid->cursor.point.col >= new_col); xassert(term->grid->cursor.point.col >= new_col);
term_cursor_left(term, term->grid->cursor.point.col - new_col); term_cursor_left(term, term->grid->cursor.point.col - new_col);
} }
break; break;

10
dcs.c
View file

@ -34,10 +34,10 @@ dcs_hook(struct terminal *term, uint8_t final)
LOG_DBG("hook: %c (intermediate(s): %.2s, param=%d)", final, LOG_DBG("hook: %c (intermediate(s): %.2s, param=%d)", final,
(const char *)&term->vt.private, vt_param_get(term, 0, 0)); (const char *)&term->vt.private, vt_param_get(term, 0, 0));
assert(term->vt.dcs.data == NULL); xassert(term->vt.dcs.data == NULL);
assert(term->vt.dcs.size == 0); xassert(term->vt.dcs.size == 0);
assert(term->vt.dcs.put_handler == NULL); xassert(term->vt.dcs.put_handler == NULL);
assert(term->vt.dcs.unhook_handler == NULL); xassert(term->vt.dcs.unhook_handler == NULL);
switch (term->vt.private) { switch (term->vt.private) {
case 0: case 0:
@ -70,7 +70,7 @@ ensure_size(struct terminal *term, size_t required_size)
return true; return true;
size_t new_size = (required_size + 127) / 128 * 128; size_t new_size = (required_size + 127) / 128 * 128;
assert(new_size > 0); xassert(new_size > 0);
uint8_t *new_data = realloc(term->vt.dcs.data, new_size); uint8_t *new_data = realloc(term->vt.dcs.data, new_size);
if (new_data == NULL) { if (new_data == NULL) {

View file

@ -8,9 +8,7 @@
#define BUG(...) bug(__FILE__, __LINE__, __func__, __VA_ARGS__) #define BUG(...) bug(__FILE__, __LINE__, __func__, __VA_ARGS__)
#endif #endif
#undef assert #define xassert(x) do { \
#define assert(x) do { \
IGNORE_WARNING("-Wtautological-compare") \ IGNORE_WARNING("-Wtautological-compare") \
if (unlikely(!(x))) { \ if (unlikely(!(x))) { \
BUG("assertion failed: '%s'", #x); \ BUG("assertion failed: '%s'", #x); \

View file

@ -46,7 +46,7 @@ ensure_size(struct extraction_context *ctx, size_t additional_chars)
ctx->size = new_size; ctx->size = new_size;
} }
assert(ctx->size >= ctx->idx + additional_chars); xassert(ctx->size >= ctx->idx + additional_chars);
return true; return true;
} }
@ -71,8 +71,8 @@ extract_finish(struct extraction_context *ctx, char **text, size_t *len)
goto out; goto out;
ctx->buf[ctx->idx++] = L'\0'; ctx->buf[ctx->idx++] = L'\0';
} else { } else {
assert(ctx->idx > 0); xassert(ctx->idx > 0);
assert(ctx->idx <= ctx->size); xassert(ctx->idx <= ctx->size);
if (ctx->buf[ctx->idx - 1] == L'\n') if (ctx->buf[ctx->idx - 1] == L'\n')
ctx->buf[ctx->idx - 1] = L'\0'; ctx->buf[ctx->idx - 1] = L'\0';
else { else {

18
fdm.c
View file

@ -84,11 +84,11 @@ fdm_destroy(struct fdm *fdm)
LOG_WARN("hook list not empty"); LOG_WARN("hook list not empty");
} }
assert(tll_length(fdm->fds) == 0); xassert(tll_length(fdm->fds) == 0);
assert(tll_length(fdm->deferred_delete) == 0); xassert(tll_length(fdm->deferred_delete) == 0);
assert(tll_length(fdm->hooks_low) == 0); xassert(tll_length(fdm->hooks_low) == 0);
assert(tll_length(fdm->hooks_normal) == 0); xassert(tll_length(fdm->hooks_normal) == 0);
assert(tll_length(fdm->hooks_high) == 0); xassert(tll_length(fdm->hooks_high) == 0);
tll_free(fdm->fds); tll_free(fdm->fds);
tll_free(fdm->deferred_delete); tll_free(fdm->deferred_delete);
@ -106,14 +106,14 @@ fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data)
int flags = fcntl(fd, F_GETFL); int flags = fcntl(fd, F_GETFL);
if (!(flags & O_NONBLOCK)) { if (!(flags & O_NONBLOCK)) {
LOG_ERR("FD=%d is in blocking mode", fd); LOG_ERR("FD=%d is in blocking mode", fd);
assert(false); xassert(false);
return false; return false;
} }
tll_foreach(fdm->fds, it) { tll_foreach(fdm->fds, it) {
if (it->item->fd == fd) { if (it->item->fd == fd) {
LOG_ERR("FD=%d already registered", fd); LOG_ERR("FD=%d already registered", fd);
assert(false); xassert(false);
return false; return false;
} }
} }
@ -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; case FDM_HOOK_PRIORITY_HIGH: return &fdm->hooks_high;
} }
assert(false); xassert(false);
return NULL; return NULL;
} }
@ -294,7 +294,7 @@ fdm_hook_del(struct fdm *fdm, fdm_hook_t hook, enum fdm_hook_priority priority)
bool bool
fdm_poll(struct fdm *fdm) fdm_poll(struct fdm *fdm)
{ {
assert(!fdm->is_polling && "nested calls to fdm_poll() not allowed"); xassert(!fdm->is_polling && "nested calls to fdm_poll() not allowed");
if (fdm->is_polling) { if (fdm->is_polling) {
LOG_ERR("nested calls to fdm_poll() not allowed"); LOG_ERR("nested calls to fdm_poll() not allowed");
return false; return false;

20
grid.c
View file

@ -14,8 +14,8 @@
void void
grid_swap_row(struct grid *grid, int row_a, int row_b) grid_swap_row(struct grid *grid, int row_a, int row_b)
{ {
assert(grid->offset >= 0); xassert(grid->offset >= 0);
assert(row_a != row_b); xassert(row_a != row_b);
int real_a = (grid->offset + row_a) & (grid->num_rows - 1); int real_a = (grid->offset + row_a) & (grid->num_rows - 1);
int real_b = (grid->offset + row_b) & (grid->num_rows - 1); int real_b = (grid->offset + row_b) & (grid->num_rows - 1);
@ -78,7 +78,7 @@ grid_resize_without_reflow(
const int new_row_idx = (new_offset + r) & (new_rows - 1); const int new_row_idx = (new_offset + r) & (new_rows - 1);
const struct row *old_row = old_grid[old_row_idx]; const struct row *old_row = old_grid[old_row_idx];
assert(old_row != NULL); xassert(old_row != NULL);
struct row *new_row = grid_row_alloc(new_cols, false); struct row *new_row = grid_row_alloc(new_cols, false);
new_grid[new_row_idx] = new_row; new_grid[new_row_idx] = new_row;
@ -188,7 +188,7 @@ grid_resize_and_reflow(
struct row **new_grid = xcalloc(new_rows, sizeof(new_grid[0])); struct row **new_grid = xcalloc(new_rows, sizeof(new_grid[0]));
struct row *new_row = new_grid[new_row_idx]; struct row *new_row = new_grid[new_row_idx];
assert(new_row == NULL); xassert(new_row == NULL);
new_row = grid_row_alloc(new_cols, true); new_row = grid_row_alloc(new_cols, true);
new_grid[new_row_idx] = new_row; new_grid[new_row_idx] = new_row;
@ -317,7 +317,7 @@ grid_resize_and_reflow(
int width = max(1, wcwidth(wc)); int width = max(1, wcwidth(wc));
/* Multi-column characters are never cut in half */ /* Multi-column characters are never cut in half */
assert(c + width <= old_cols); xassert(c + width <= old_cols);
for (int i = 0; i < empty_count + 1; i++) { for (int i = 0; i < empty_count + 1; i++) {
const struct cell *old_cell = &old_row->cells[c - empty_count + i]; const struct cell *old_cell = &old_row->cells[c - empty_count + i];
@ -340,9 +340,9 @@ grid_resize_and_reflow(
line_wrap(); line_wrap();
} }
assert(new_row != NULL); xassert(new_row != NULL);
assert(new_col_idx >= 0); xassert(new_col_idx >= 0);
assert(new_col_idx < new_cols); xassert(new_col_idx < new_cols);
new_row->cells[new_col_idx] = *old_cell; new_row->cells[new_col_idx] = *old_cell;
new_row->cells[new_col_idx].attrs.clean = 1; new_row->cells[new_col_idx].attrs.clean = 1;
@ -364,7 +364,7 @@ grid_resize_and_reflow(
* subsequent cells */ * subsequent cells */
const struct cell *old_cell = &old_row->cells[c]; const struct cell *old_cell = &old_row->cells[c];
for (size_t i = 0; i < width - 1; i++) { for (size_t i = 0; i < width - 1; i++) {
assert(new_col_idx < new_cols); xassert(new_col_idx < new_cols);
print_spacer(); print_spacer();
new_col_idx++; new_col_idx++;
} }
@ -410,7 +410,7 @@ grid_resize_and_reflow(
} }
for (size_t r = 0; r < new_screen_rows; r++) { for (size_t r = 0; r < new_screen_rows; r++) {
int UNUSED idx = (grid->view + r) & (new_rows - 1); int UNUSED idx = (grid->view + r) & (new_rows - 1);
assert(new_grid[idx] != NULL); xassert(new_grid[idx] != NULL);
} }
/* Free old grid */ /* Free old grid */

9
grid.h
View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "debug.h"
#include "terminal.h" #include "terminal.h"
void grid_swap_row(struct grid *grid, int row_a, int row_b); void grid_swap_row(struct grid *grid, int row_a, int row_b);
@ -34,7 +35,7 @@ grid_row_absolute_in_view(const struct grid *grid, int row_no)
static inline struct row * static inline struct row *
_grid_row_maybe_alloc(struct grid *grid, int row_no, bool alloc_if_null) _grid_row_maybe_alloc(struct grid *grid, int row_no, bool alloc_if_null)
{ {
assert(grid->offset >= 0); xassert(grid->offset >= 0);
int real_row = grid_row_absolute(grid, row_no); int real_row = grid_row_absolute(grid, row_no);
struct row *row = grid->rows[real_row]; struct row *row = grid->rows[real_row];
@ -44,7 +45,7 @@ _grid_row_maybe_alloc(struct grid *grid, int row_no, bool alloc_if_null)
grid->rows[real_row] = row; grid->rows[real_row] = row;
} }
assert(row != NULL); xassert(row != NULL);
return row; return row;
} }
@ -63,11 +64,11 @@ grid_row_and_alloc(struct grid *grid, int row_no)
static inline struct row * static inline struct row *
grid_row_in_view(struct grid *grid, int row_no) grid_row_in_view(struct grid *grid, int row_no)
{ {
assert(grid->view >= 0); xassert(grid->view >= 0);
int real_row = grid_row_absolute_in_view(grid, row_no); int real_row = grid_row_absolute_in_view(grid, row_no);
struct row *row = grid->rows[real_row]; struct row *row = grid->rows[real_row];
assert(row != NULL); xassert(row != NULL);
return row; return row;
} }

18
ime.c
View file

@ -27,8 +27,8 @@ enter(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
/* The main grid is the *only* input-receiving surface we have */ /* The main grid is the *only* input-receiving surface we have */
/* TODO: can we receive text_input::enter() _before_ keyboard_enter()? */ /* TODO: can we receive text_input::enter() _before_ keyboard_enter()? */
struct terminal UNUSED *term = seat->kbd_focus; struct terminal UNUSED *term = seat->kbd_focus;
assert(term != NULL); xassert(term != NULL);
assert(term_surface_kind(term, surface) == TERM_SURF_GRID); xassert(term_surface_kind(term, surface) == TERM_SURF_GRID);
ime_enable(seat); ime_enable(seat);
} }
@ -111,7 +111,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
return; return;
} }
assert(seat->kbd_focus); xassert(seat->kbd_focus);
struct terminal *term = seat->kbd_focus; struct terminal *term = seat->kbd_focus;
/* 1. Delete existing pre-edit text */ /* 1. Delete existing pre-edit text */
@ -272,11 +272,11 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
LOG_DBG("pre-edit cursor: begin=%d, end=%d", cell_begin, cell_end); LOG_DBG("pre-edit cursor: begin=%d, end=%d", cell_begin, cell_end);
assert(cell_begin >= 0); xassert(cell_begin >= 0);
assert(cell_begin < cell_count); xassert(cell_begin < cell_count);
assert(cell_begin <= cell_end); xassert(cell_begin <= cell_end);
assert(cell_end >= 0); xassert(cell_end >= 0);
assert(cell_end <= cell_count); xassert(cell_end <= cell_count);
term->ime.preedit.cursor.hidden = false; term->ime.preedit.cursor.hidden = false;
term->ime.preedit.cursor.start = cell_begin; term->ime.preedit.cursor.start = cell_begin;
@ -331,7 +331,7 @@ ime_enable(struct seat *seat)
return; return;
struct terminal *term = seat->kbd_focus; struct terminal *term = seat->kbd_focus;
assert(term != NULL); xassert(term != NULL);
if (!term->ime.enabled) if (!term->ime.enabled)
return; return;

56
input.c
View file

@ -53,7 +53,7 @@ fdm_write_pipe(struct fdm *fdm, int fd, int events, void *data)
if (events & EPOLLHUP) if (events & EPOLLHUP)
goto pipe_closed; goto pipe_closed;
assert(events & EPOLLOUT); xassert(events & EPOLLOUT);
ssize_t written = write(fd, &ctx->text[ctx->idx], ctx->left); ssize_t written = write(fd, &ctx->text[ctx->idx], ctx->left);
if (written < 0) { if (written < 0) {
@ -61,7 +61,7 @@ fdm_write_pipe(struct fdm *fdm, int fd, int events, void *data)
goto pipe_closed; goto pipe_closed;
} }
assert(written <= ctx->left); xassert(written <= ctx->left);
ctx->idx += written; ctx->idx += written;
ctx->left -= written; ctx->left -= written;
@ -210,7 +210,7 @@ execute_binding(struct seat *seat, struct terminal *term,
break; break;
default: default:
assert(false); xassert(false);
success = false; success = false;
break; break;
} }
@ -332,7 +332,7 @@ execute_binding(struct seat *seat, struct terminal *term,
return false; return false;
case BIND_ACTION_COUNT: case BIND_ACTION_COUNT:
assert(false); xassert(false);
return false; return false;
} }
@ -557,7 +557,7 @@ static void
keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial,
struct wl_surface *surface, struct wl_array *keys) struct wl_surface *surface, struct wl_array *keys)
{ {
assert(surface != NULL); xassert(surface != NULL);
struct seat *seat = data; struct seat *seat = data;
struct wl_window *win = wl_surface_get_user_data(surface); struct wl_window *win = wl_surface_get_user_data(surface);
@ -631,7 +631,7 @@ keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial,
if (seat->kbd.xkb == NULL) if (seat->kbd.xkb == NULL)
return; return;
assert( xassert(
seat->kbd_focus == NULL || seat->kbd_focus == NULL ||
surface == NULL || /* Seen on Sway 1.2 */ surface == NULL || /* Seen on Sway 1.2 */
((const struct wl_window *)wl_surface_get_user_data(surface))->term == seat->kbd_focus ((const struct wl_window *)wl_surface_get_user_data(surface))->term == seat->kbd_focus
@ -923,7 +923,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
* Compose, and maybe emit "normal" character * Compose, and maybe emit "normal" character
*/ */
assert(seat->kbd.xkb_compose_state != NULL || xassert(seat->kbd.xkb_compose_state != NULL ||
compose_status != XKB_COMPOSE_COMPOSED); compose_status != XKB_COMPOSE_COMPOSED);
int count = compose_status == XKB_COMPOSE_COMPOSED int count = compose_status == XKB_COMPOSE_COMPOSED
@ -973,9 +973,9 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial,
[MOD_META | MOD_SHIFT | MOD_ALT | MOD_CTRL] = 16, [MOD_META | MOD_SHIFT | MOD_ALT | MOD_CTRL] = 16,
}; };
assert(keymap_mods < sizeof(mod_param_map) / sizeof(mod_param_map[0])); xassert(keymap_mods < sizeof(mod_param_map) / sizeof(mod_param_map[0]));
int modify_param = mod_param_map[keymap_mods]; int modify_param = mod_param_map[keymap_mods];
assert(modify_param != 0); xassert(modify_param != 0);
char reply[1024]; char reply[1024];
size_t n = xsnprintf(reply, sizeof(reply), "\x1b[27;%d;%d~", modify_param, sym); size_t n = xsnprintf(reply, sizeof(reply), "\x1b[27;%d;%d~", modify_param, sym);
@ -1101,7 +1101,7 @@ void
input_repeat(struct seat *seat, uint32_t key) input_repeat(struct seat *seat, uint32_t key)
{ {
/* Should be cleared as soon as we loose focus */ /* Should be cleared as soon as we loose focus */
assert(seat->kbd_focus != NULL); xassert(seat->kbd_focus != NULL);
struct terminal *term = seat->kbd_focus; struct terminal *term = seat->kbd_focus;
key_press_release(seat, term, seat->kbd.serial, key, XKB_KEY_DOWN); key_press_release(seat, term, seat->kbd.serial, key, XKB_KEY_DOWN);
@ -1161,7 +1161,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_TOP) return XCURSOR_TOP_SIDE;
else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) return XCURSOR_BOTTOM_SIDE; else if (term->active_surface == TERM_SURF_BORDER_BOTTOM) return XCURSOR_BOTTOM_SIDE;
else { else {
assert(false); xassert(false);
return NULL; return NULL;
} }
} }
@ -1171,7 +1171,7 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface, uint32_t serial, struct wl_surface *surface,
wl_fixed_t surface_x, wl_fixed_t surface_y) wl_fixed_t surface_x, wl_fixed_t surface_y)
{ {
assert(surface != NULL); xassert(surface != NULL);
struct seat *seat = data; struct seat *seat = data;
struct wl_window *win = wl_surface_get_user_data(surface); struct wl_window *win = wl_surface_get_user_data(surface);
@ -1235,7 +1235,7 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
break; break;
case TERM_SURF_NONE: case TERM_SURF_NONE:
assert(false); xassert(false);
break; break;
} }
} }
@ -1281,7 +1281,7 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
if (surface != NULL) { if (surface != NULL) {
/* Sway 1.4 sends this event with a NULL surface when we destroy the window */ /* Sway 1.4 sends this event with a NULL surface when we destroy the window */
const struct wl_window UNUSED *win = wl_surface_get_user_data(surface); const struct wl_window UNUSED *win = wl_surface_get_user_data(surface);
assert(old_moused == win->term); xassert(old_moused == win->term);
} }
enum term_surface active_surface = old_moused->active_surface; enum term_surface active_surface = old_moused->active_surface;
@ -1327,7 +1327,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
LOG_DBG("pointer_motion: pointer=%p, x=%d, y=%d", (void *)wl_pointer, LOG_DBG("pointer_motion: pointer=%p, x=%d, y=%d", (void *)wl_pointer,
wl_fixed_to_int(surface_x), wl_fixed_to_int(surface_y)); wl_fixed_to_int(surface_x), wl_fixed_to_int(surface_y));
assert(term != NULL); xassert(term != NULL);
int x = wl_fixed_to_int(surface_x) * term->scale; int x = wl_fixed_to_int(surface_x) * term->scale;
int y = wl_fixed_to_int(surface_y) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale;
@ -1420,8 +1420,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
seat->mouse.row = selection_row; seat->mouse.row = selection_row;
} }
assert(seat->mouse.col == -1 || (seat->mouse.col >= 0 && seat->mouse.col < term->cols)); xassert(seat->mouse.col == -1 || (seat->mouse.col >= 0 && seat->mouse.col < term->cols));
assert(seat->mouse.row == -1 || (seat->mouse.row >= 0 && seat->mouse.row < term->rows)); xassert(seat->mouse.row == -1 || (seat->mouse.row >= 0 && seat->mouse.row < term->rows));
term_xcursor_update_for_seat(term, seat); term_xcursor_update_for_seat(term, seat);
@ -1461,7 +1461,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
? term->margins.top - y ? term->margins.top - y
: y - (term->height - term->margins.bottom); : y - (term->height - term->margins.bottom);
assert(distance > 0); xassert(distance > 0);
int divisor int divisor
= distance * term->conf->scrollback.multiplier / term->scale; = distance * term->conf->scrollback.multiplier / term->scale;
@ -1483,8 +1483,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
((button == 0 && cursor_is_on_grid) || ((button == 0 && cursor_is_on_grid) ||
(button != 0 && send_to_client))) (button != 0 && send_to_client)))
{ {
assert(seat->mouse.col < term->cols); xassert(seat->mouse.col < term->cols);
assert(seat->mouse.row < term->rows); xassert(seat->mouse.row < term->rows);
term_mouse_motion( term_mouse_motion(
term, button, term, button,
@ -1529,7 +1529,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
seat->pointer.hidden = false; seat->pointer.hidden = false;
assert(term != NULL); xassert(term != NULL);
enum term_surface surf_kind = TERM_SURF_NONE; enum term_surface surf_kind = TERM_SURF_NONE;
bool send_to_client = false; bool send_to_client = false;
@ -1549,7 +1549,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
#if defined(_DEBUG) #if defined(_DEBUG)
tll_foreach(seat->mouse.buttons, it) tll_foreach(seat->mouse.buttons, it)
assert(it->item.button != button); xassert(it->item.button != button);
#endif #endif
/* /*
@ -1811,7 +1811,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
} }
case TERM_SURF_NONE: case TERM_SURF_NONE:
assert(false); xassert(false);
break; break;
} }
@ -1824,7 +1824,7 @@ alternate_scroll(struct seat *seat, int amount, int button)
return; return;
/* Should be cleared in leave event */ /* Should be cleared in leave event */
assert(seat->mouse_focus != NULL); xassert(seat->mouse_focus != NULL);
struct terminal *term = seat->mouse_focus; struct terminal *term = seat->mouse_focus;
xkb_keycode_t key = button == BTN_BACK xkb_keycode_t key = button == BTN_BACK
@ -1839,7 +1839,7 @@ static void
mouse_scroll(struct seat *seat, int amount) mouse_scroll(struct seat *seat, int amount)
{ {
struct terminal *term = seat->mouse_focus; struct terminal *term = seat->mouse_focus;
assert(term != NULL); xassert(term != NULL);
int button = amount < 0 ? BTN_BACK : BTN_FORWARD; int button = amount < 0 ? BTN_BACK : BTN_FORWARD;
amount = abs(amount); amount = abs(amount);
@ -1857,8 +1857,8 @@ mouse_scroll(struct seat *seat, int amount)
} else if (!term_mouse_grabbed(term, seat) && } else if (!term_mouse_grabbed(term, seat) &&
seat->mouse.col >= 0 && seat->mouse.row >= 0) seat->mouse.col >= 0 && seat->mouse.row >= 0)
{ {
assert(seat->mouse.col < term->cols); xassert(seat->mouse.col < term->cols);
assert(seat->mouse.row < term->rows); xassert(seat->mouse.row < term->rows);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
term_mouse_down( term_mouse_down(
@ -1884,7 +1884,7 @@ wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
if (seat->mouse.have_discrete) if (seat->mouse.have_discrete)
return; return;
assert(seat->mouse_focus != NULL); xassert(seat->mouse_focus != NULL);
/* /*
* Aggregate scrolled amount until we get at least 1.0 * Aggregate scrolled amount until we get at least 1.0

4
log.c
View file

@ -94,11 +94,11 @@ _sys_log(enum log_class log_class, const char *module,
case LOG_CLASS_DEBUG: level = LOG_DEBUG; break; case LOG_CLASS_DEBUG: level = LOG_DEBUG; break;
} }
assert(level != -1); xassert(level != -1);
char msg[4096]; char msg[4096];
int n = vsnprintf(msg, sizeof(msg), fmt, va); int n = vsnprintf(msg, sizeof(msg), fmt, va);
assert(n >= 0); xassert(n >= 0);
if (sys_errno != 0 && (size_t)n < sizeof(msg)) if (sys_errno != 0 && (size_t)n < sizeof(msg))
snprintf(msg + n, sizeof(msg) - n, ": %s", strerror(sys_errno)); snprintf(msg + n, sizeof(msg) - n, ": %s", strerror(sys_errno));

4
main.c
View file

@ -82,7 +82,7 @@ print_usage(const char *prog_name)
bool bool
locale_is_utf8(void) locale_is_utf8(void)
{ {
assert(strlen(u8"ö") == 2); xassert(strlen(u8"ö") == 2);
wchar_t w; wchar_t w;
if (mbtowc(&w, u8"ö", 2) != 2) if (mbtowc(&w, u8"ö", 2) != 2)
@ -240,7 +240,7 @@ main(int argc, char *const *argv)
/* Strip trailing spaces */ /* Strip trailing spaces */
char *end = font + strlen(font); char *end = font + strlen(font);
assert(*end == '\0'); xassert(*end == '\0');
end--; end--;
while (end > font && isspace(*end)) while (end > font && isspace(*end))
*(end--) = '\0'; *(end--) = '\0';

22
osc.c
View file

@ -106,7 +106,7 @@ from_clipboard_cb(char *text, size_t size, void *user)
struct clip_context *ctx = user; struct clip_context *ctx = user;
struct terminal *term = ctx->term; struct terminal *term = ctx->term;
assert(ctx->idx >= 0 && ctx->idx <= 2); xassert(ctx->idx >= 0 && ctx->idx <= 2);
const char *t = text; const char *t = text;
size_t left = size; size_t left = size;
@ -115,11 +115,11 @@ from_clipboard_cb(char *text, size_t size, void *user)
for (size_t i = ctx->idx; i < 3 && left > 0; i++, t++, left--) for (size_t i = ctx->idx; i < 3 && left > 0; i++, t++, left--)
ctx->buf[ctx->idx++] = *t; ctx->buf[ctx->idx++] = *t;
assert(ctx->idx <= 3); xassert(ctx->idx <= 3);
if (ctx->idx == 3) { if (ctx->idx == 3) {
char *chunk = base64_encode(ctx->buf, 3); char *chunk = base64_encode(ctx->buf, 3);
assert(chunk != NULL); xassert(chunk != NULL);
assert(strlen(chunk) == 4); xassert(strlen(chunk) == 4);
term_to_slave(term, chunk, 4); term_to_slave(term, chunk, 4);
free(chunk); free(chunk);
@ -131,16 +131,16 @@ from_clipboard_cb(char *text, size_t size, void *user)
if (left == 0) if (left == 0)
return; return;
assert(ctx->idx == 0); xassert(ctx->idx == 0);
int remaining = left % 3; int remaining = left % 3;
for (int i = remaining; i > 0; i--) for (int i = remaining; i > 0; i--)
ctx->buf[ctx->idx++] = text[size - i]; ctx->buf[ctx->idx++] = text[size - i];
assert(ctx->idx == remaining); xassert(ctx->idx == remaining);
char *chunk = base64_encode((const uint8_t *)t, left / 3 * 3); char *chunk = base64_encode((const uint8_t *)t, left / 3 * 3);
assert(chunk != NULL); xassert(chunk != NULL);
assert(strlen(chunk) % 4 == 0); xassert(strlen(chunk) % 4 == 0);
term_to_slave(term, chunk, strlen(chunk)); term_to_slave(term, chunk, strlen(chunk));
free(chunk); free(chunk);
} }
@ -437,7 +437,7 @@ update_color_in_grids(struct terminal *term, uint32_t old_color,
for (size_t r = 0; r < term->rows; r++) { for (size_t r = 0; r < term->rows; r++) {
struct row *row = grid_row(grid, r); struct row *row = grid_row(grid, r);
assert(row != NULL); xassert(row != NULL);
for (size_t c = 0; c < term->grid->num_cols; c++) { for (size_t c = 0; c < term->grid->num_cols; c++) {
struct cell *cell = &row->cells[c]; struct cell *cell = &row->cells[c];
@ -501,7 +501,7 @@ osc_dispatch(struct terminal *term)
if (*string != ';') if (*string != ';')
break; break;
assert(*string == ';'); xassert(*string == ';');
for (const char *s_idx = strtok(string, ";"), *s_color = strtok(NULL, ";"); for (const char *s_idx = strtok(string, ";"), *s_color = strtok(NULL, ";");
s_idx != NULL && s_color != NULL; s_idx != NULL && s_color != NULL;
@ -725,7 +725,7 @@ osc_ensure_size(struct terminal *term, size_t required_size)
return true; return true;
size_t new_size = (required_size + 127) / 128 * 128; size_t new_size = (required_size + 127) / 128 * 128;
assert(new_size > 0); xassert(new_size > 0);
uint8_t *new_data = realloc(term->vt.osc.data, new_size); uint8_t *new_data = realloc(term->vt.osc.data, new_size);
if (new_data == NULL) { if (new_data == NULL) {

View file

@ -121,7 +121,7 @@ fdm_reap(struct fdm *fdm, int fd, int events, void *data)
if (hup && !pollin) if (hup && !pollin)
return false; return false;
assert(pollin); xassert(pollin);
struct signalfd_siginfo info; struct signalfd_siginfo info;
ssize_t amount = read(reaper->fd, &info, sizeof(info)); ssize_t amount = read(reaper->fd, &info, sizeof(info));
@ -131,7 +131,7 @@ fdm_reap(struct fdm *fdm, int fd, int events, void *data)
return false; return false;
} }
assert((size_t)amount >= sizeof(info)); xassert((size_t)amount >= sizeof(info));
if (info.ssi_signo != SIGCHLD) { if (info.ssi_signo != SIGCHLD) {
LOG_WARN("got non-SIGCHLD signal: %d", info.ssi_signo); LOG_WARN("got non-SIGCHLD signal: %d", info.ssi_signo);

132
render.c
View file

@ -150,10 +150,10 @@ presented(void *data,
"commit - %llu µs -> ", (unsigned long long)diff.tv_usec); "commit - %llu µs -> ", (unsigned long long)diff.tv_usec);
if (use_input) { if (use_input) {
assert(timercmp(&presented, input, >)); xassert(timercmp(&presented, input, >));
timersub(&presented, input, &diff); timersub(&presented, input, &diff);
} else { } else {
assert(timercmp(&presented, commit, >)); xassert(timercmp(&presented, commit, >));
timersub(&presented, commit, &diff); timersub(&presented, commit, &diff);
} }
@ -396,7 +396,7 @@ render_cell(struct terminal *term, pixman_image_t *pix,
int x = term->margins.left + col * width; int x = term->margins.left + col * width;
int y = term->margins.top + row_no * height; int y = term->margins.top + row_no * height;
assert(cell->attrs.selected == 0 || cell->attrs.selected == 1); xassert(cell->attrs.selected == 0 || cell->attrs.selected == 1);
bool is_selected = cell->attrs.selected; bool is_selected = cell->attrs.selected;
uint32_t _fg = 0; uint32_t _fg = 0;
@ -454,7 +454,7 @@ render_cell(struct terminal *term, pixman_image_t *pix,
(base >= 0x1fb00 && base <= 0x1fb3b))) { (base >= 0x1fb00 && base <= 0x1fb3b))) {
/* Box drawing characters */ /* Box drawing characters */
size_t idx = base >= 0x1fb00 ? base - 0x1fb00 + 160 : base - 0x2500; size_t idx = base >= 0x1fb00 ? base - 0x1fb00 + 160 : base - 0x2500;
assert(idx < ALEN(term->box_drawing)); xassert(idx < ALEN(term->box_drawing));
if (likely(term->box_drawing[idx] != NULL)) if (likely(term->box_drawing[idx] != NULL))
glyph = term->box_drawing[idx]; glyph = term->box_drawing[idx];
@ -467,7 +467,7 @@ render_cell(struct terminal *term, pixman_image_t *pix,
mtx_unlock(&term->render.workers.lock); mtx_unlock(&term->render.workers.lock);
glyph = term->box_drawing[idx]; glyph = term->box_drawing[idx];
assert(glyph != NULL); xassert(glyph != NULL);
} }
} else } else
glyph = fcft_glyph_rasterize(font, base, term->font_subpixel); glyph = fcft_glyph_rasterize(font, base, term->font_subpixel);
@ -893,10 +893,10 @@ render_sixel_chunk(struct terminal *term, pixman_image_t *pix, const struct sixe
term->height - y - term->margins.bottom)); term->height - y - term->margins.bottom));
/* Verify we're not stepping outside the grid */ /* Verify we're not stepping outside the grid */
assert(x >= term->margins.left); xassert(x >= term->margins.left);
assert(y >= term->margins.top); xassert(y >= term->margins.top);
assert(width == 0 || x + width <= term->width - term->margins.right); xassert(width == 0 || x + width <= term->width - term->margins.right);
assert(height == 0 || y + height <= term->height - term->margins.bottom); xassert(height == 0 || y + height <= term->height - term->margins.bottom);
//LOG_DBG("sixel chunk: %dx%d %dx%d", x, y, width, height); //LOG_DBG("sixel chunk: %dx%d %dx%d", x, y, width, height);
@ -980,7 +980,7 @@ render_sixel(struct terminal *term, pixman_image_t *pix,
/* Is the row dirty? */ /* Is the row dirty? */
struct row *row = term->grid->rows[abs_row_no]; struct row *row = term->grid->rows[abs_row_no];
assert(row != NULL); /* Should be visible */ xassert(row != NULL); /* Should be visible */
if (!row->dirty) { if (!row->dirty) {
maybe_emit_sixel_chunk_then_reset(); maybe_emit_sixel_chunk_then_reset();
@ -1014,7 +1014,7 @@ render_sixel(struct terminal *term, pixman_image_t *pix,
} }
if (chunk_term_start == -1) { if (chunk_term_start == -1) {
assert(chunk_img_start == -1); xassert(chunk_img_start == -1);
chunk_term_start = term_row_no; chunk_term_start = term_row_no;
chunk_img_start = _abs_row_no - sixel->pos.row; chunk_img_start = _abs_row_no - sixel->pos.row;
chunk_row_count = 1; chunk_row_count = 1;
@ -1125,8 +1125,8 @@ render_ime_preedit(struct terminal *term, struct buffer *buf)
} }
} }
assert(col_idx >= 0); xassert(col_idx >= 0);
assert(col_idx < term->cols); xassert(col_idx < term->cols);
struct row *row = grid_row_in_view(term->grid, row_idx); struct row *row = grid_row_in_view(term->grid, row_idx);
@ -1143,14 +1143,14 @@ render_ime_preedit(struct terminal *term, struct buffer *buf)
*/ */
struct cell *real_cells = malloc(cells_used * sizeof(real_cells[0])); struct cell *real_cells = malloc(cells_used * sizeof(real_cells[0]));
for (int i = 0; i < cells_used; i++) { for (int i = 0; i < cells_used; i++) {
assert(col_idx + i < term->cols); xassert(col_idx + i < term->cols);
real_cells[i] = row->cells[col_idx + i]; real_cells[i] = row->cells[col_idx + i];
real_cells[i].attrs.clean = 0; real_cells[i].attrs.clean = 0;
} }
row->dirty = true; row->dirty = true;
/* Render pre-edit text */ /* Render pre-edit text */
assert(term->ime.preedit.cells[ime_ofs].wc != CELL_MULT_COL_SPACER); xassert(term->ime.preedit.cells[ime_ofs].wc != CELL_MULT_COL_SPACER);
for (int i = 0, idx = ime_ofs; idx < term->ime.preedit.count; i++, idx++) { for (int i = 0, idx = ime_ofs; idx < term->ime.preedit.count; i++, idx++) {
const struct cell *cell = &term->ime.preedit.cells[idx]; const struct cell *cell = &term->ime.preedit.cells[idx];
@ -1255,14 +1255,14 @@ render_worker_thread(void *_ctx)
while (!frame_done) { while (!frame_done) {
mtx_lock(lock); mtx_lock(lock);
assert(tll_length(term->render.workers.queue) > 0); xassert(tll_length(term->render.workers.queue) > 0);
int row_no = tll_pop_front(term->render.workers.queue); int row_no = tll_pop_front(term->render.workers.queue);
mtx_unlock(lock); mtx_unlock(lock);
switch (row_no) { switch (row_no) {
default: { default: {
assert(buf != NULL); xassert(buf != NULL);
struct row *row = grid_row_in_view(term->grid, row_no); struct row *row = grid_row_in_view(term->grid, row_no);
int cursor_col = cursor.row == row_no ? cursor.col : -1; int cursor_col = cursor.row == row_no ? cursor.col : -1;
@ -1295,7 +1295,7 @@ struct csd_data {
static struct csd_data static struct csd_data
get_csd_data(const struct terminal *term, enum csd_surface surf_idx) get_csd_data(const struct terminal *term, enum csd_surface surf_idx)
{ {
assert(term->window->use_csd == CSD_YES); xassert(term->window->use_csd == CSD_YES);
/* Only title bar is rendered in maximized mode */ /* Only title bar is rendered in maximized mode */
const int border_width = !term->window->is_maximized const int border_width = !term->window->is_maximized
@ -1330,11 +1330,11 @@ 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_CLOSE: return (struct csd_data){term->width - 1 * button_width, 0, button_close_width, title_height};
case CSD_SURF_COUNT: case CSD_SURF_COUNT:
assert(false); xassert(false);
return (struct csd_data){0}; return (struct csd_data){0};
} }
assert(false); xassert(false);
return (struct csd_data){0}; return (struct csd_data){0};
} }
@ -1352,7 +1352,7 @@ render_csd_part(struct terminal *term,
struct wl_surface *surf, struct buffer *buf, struct wl_surface *surf, struct buffer *buf,
int width, int height, pixman_color_t *color) int width, int height, pixman_color_t *color)
{ {
assert(term->window->use_csd == CSD_YES); xassert(term->window->use_csd == CSD_YES);
pixman_image_t *src = pixman_image_create_solid_fill(color); pixman_image_t *src = pixman_image_create_solid_fill(color);
@ -1365,12 +1365,12 @@ render_csd_part(struct terminal *term,
static void static void
render_csd_title(struct terminal *term) render_csd_title(struct terminal *term)
{ {
assert(term->window->use_csd == CSD_YES); xassert(term->window->use_csd == CSD_YES);
struct csd_data info = get_csd_data(term, CSD_SURF_TITLE); struct csd_data info = get_csd_data(term, CSD_SURF_TITLE);
struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE]; struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE];
assert(info.width > 0 && info.height > 0); xassert(info.width > 0 && info.height > 0);
unsigned long cookie = shm_cookie_csd(term, CSD_SURF_TITLE); unsigned long cookie = shm_cookie_csd(term, CSD_SURF_TITLE);
struct buffer *buf = shm_get_buffer( struct buffer *buf = shm_get_buffer(
@ -1395,8 +1395,8 @@ render_csd_title(struct terminal *term)
static void static void
render_csd_border(struct terminal *term, enum csd_surface surf_idx) render_csd_border(struct terminal *term, enum csd_surface surf_idx)
{ {
assert(term->window->use_csd == CSD_YES); xassert(term->window->use_csd == CSD_YES);
assert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM); xassert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM);
struct csd_data info = get_csd_data(term, surf_idx); struct csd_data info = get_csd_data(term, surf_idx);
struct wl_surface *surf = term->window->csd.surface[surf_idx]; struct wl_surface *surf = term->window->csd.surface[surf_idx];
@ -1430,8 +1430,8 @@ render_csd_button_minimize(struct terminal *term, struct buffer *buf)
width = height * 2; width = height * 2;
} }
assert(width <= max_width); xassert(width <= max_width);
assert(height <= max_height); xassert(height <= max_height);
int x_margin = (buf->width - width) / 2.; int x_margin = (buf->width - width) / 2.;
int y_margin = (buf->height - height) / 2.; int y_margin = (buf->height - height) / 2.;
@ -1503,8 +1503,8 @@ render_csd_button_maximize_window(
width = height * 2; width = height * 2;
} }
assert(width <= max_width); xassert(width <= max_width);
assert(height <= max_height); xassert(height <= max_height);
int x_margin = (buf->width - width) / 2.; int x_margin = (buf->width - width) / 2.;
int y_margin = (buf->height - height) / 2.; int y_margin = (buf->height - height) / 2.;
@ -1564,8 +1564,8 @@ render_csd_button_close(struct terminal *term, struct buffer *buf)
static void static void
render_csd_button(struct terminal *term, enum csd_surface surf_idx) render_csd_button(struct terminal *term, enum csd_surface surf_idx)
{ {
assert(term->window->use_csd == CSD_YES); xassert(term->window->use_csd == CSD_YES);
assert(surf_idx >= CSD_SURF_MINIMIZE && surf_idx <= CSD_SURF_CLOSE); xassert(surf_idx >= CSD_SURF_MINIMIZE && surf_idx <= CSD_SURF_CLOSE);
struct csd_data info = get_csd_data(term, surf_idx); struct csd_data info = get_csd_data(term, surf_idx);
struct wl_surface *surf = term->window->csd.surface[surf_idx]; struct wl_surface *surf = term->window->csd.surface[surf_idx];
@ -1606,7 +1606,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx)
break; break;
default: default:
assert(false); xassert(false);
break; break;
} }
@ -1633,7 +1633,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx)
break; break;
default: default:
assert(false); xassert(false);
break; break;
} }
@ -1643,7 +1643,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx)
static void static void
render_csd(struct terminal *term) render_csd(struct terminal *term)
{ {
assert(term->window->use_csd == CSD_YES); xassert(term->window->use_csd == CSD_YES);
if (term->window->is_fullscreen) if (term->window->is_fullscreen)
return; return;
@ -1658,8 +1658,8 @@ render_csd(struct terminal *term)
struct wl_surface *surf = term->window->csd.surface[i]; struct wl_surface *surf = term->window->csd.surface[i];
struct wl_subsurface *sub = term->window->csd.sub_surface[i]; struct wl_subsurface *sub = term->window->csd.sub_surface[i];
assert(surf != NULL); xassert(surf != NULL);
assert(sub != NULL); xassert(sub != NULL);
if (width == 0 || height == 0) { if (width == 0 || height == 0) {
wl_subsurface_set_position(sub, 0, 0); wl_subsurface_set_position(sub, 0, 0);
@ -1775,8 +1775,8 @@ render_scrollback_position(struct terminal *term)
wl_subsurface_set_sync(win->scrollback_indicator_sub_surface); wl_subsurface_set_sync(win->scrollback_indicator_sub_surface);
} }
assert(win->scrollback_indicator_surface != NULL); xassert(win->scrollback_indicator_surface != NULL);
assert(win->scrollback_indicator_sub_surface != NULL); xassert(win->scrollback_indicator_sub_surface != NULL);
/* Find absolute row number of the scrollback start */ /* Find absolute row number of the scrollback start */
int scrollback_start = term->grid->offset + term->rows; int scrollback_start = term->grid->offset + term->rows;
@ -1793,8 +1793,8 @@ render_scrollback_position(struct terminal *term)
/* How much of the scrollback is actually used? */ /* How much of the scrollback is actually used? */
int populated_rows = term->grid->num_rows - empty_rows; int populated_rows = term->grid->num_rows - empty_rows;
assert(populated_rows > 0); xassert(populated_rows > 0);
assert(populated_rows <= term->grid->num_rows); xassert(populated_rows <= term->grid->num_rows);
/* /*
* How far down in the scrollback we are. * How far down in the scrollback we are.
@ -1842,7 +1842,7 @@ render_scrollback_position(struct terminal *term)
int surf_top = 0; int surf_top = 0;
switch (term->conf->scrollback.indicator.position) { switch (term->conf->scrollback.indicator.position) {
case SCROLLBACK_INDICATOR_POSITION_NONE: case SCROLLBACK_INDICATOR_POSITION_NONE:
assert(false); xassert(false);
return; return;
case SCROLLBACK_INDICATOR_POSITION_FIXED: case SCROLLBACK_INDICATOR_POSITION_FIXED:
@ -1855,7 +1855,7 @@ render_scrollback_position(struct terminal *term)
/* Make sure we don't collide with the scrollback search box */ /* Make sure we don't collide with the scrollback search box */
lines--; lines--;
} }
assert(lines > 0); xassert(lines > 0);
int pixels = lines * term->cell_height - height + 2 * margin; int pixels = lines * term->cell_height - height + 2 * margin;
surf_top = term->cell_height - margin + (int)(percent * pixels); surf_top = term->cell_height - margin + (int)(percent * pixels);
@ -1925,8 +1925,8 @@ grid_render(struct terminal *term)
if (term->conf->tweak.render_timer_osd || term->conf->tweak.render_timer_log) if (term->conf->tweak.render_timer_osd || term->conf->tweak.render_timer_log)
gettimeofday(&start_time, NULL); gettimeofday(&start_time, NULL);
assert(term->width > 0); xassert(term->width > 0);
assert(term->height > 0); xassert(term->height > 0);
unsigned long cookie = shm_cookie_grid(term); unsigned long cookie = shm_cookie_grid(term);
struct buffer *buf = shm_get_buffer( struct buffer *buf = shm_get_buffer(
@ -1955,7 +1955,7 @@ grid_render(struct terminal *term)
has_warned = true; has_warned = true;
} }
assert(term->render.last_buf->size == buf->size); xassert(term->render.last_buf->size == buf->size);
memcpy(buf->mmapped, term->render.last_buf->mmapped, buf->size); memcpy(buf->mmapped, term->render.last_buf->mmapped, buf->size);
} }
@ -2054,7 +2054,7 @@ grid_render(struct terminal *term)
for (size_t i = 0; i < term->render.workers.count; i++) for (size_t i = 0; i < term->render.workers.count; i++)
sem_post(&term->render.workers.start); sem_post(&term->render.workers.start);
assert(tll_length(term->render.workers.queue) == 0); xassert(tll_length(term->render.workers.queue) == 0);
} }
int first_dirty_row = -1; int first_dirty_row = -1;
@ -2142,10 +2142,10 @@ grid_render(struct terminal *term)
render_render_timer(term, render_time); render_render_timer(term, render_time);
} }
assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows); xassert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows);
assert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows); xassert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows);
assert(term->window->frame_callback == NULL); xassert(term->window->frame_callback == NULL);
term->window->frame_callback = wl_surface_frame(term->window->surface); term->window->frame_callback = wl_surface_frame(term->window->surface);
wl_callback_add_listener(term->window->frame_callback, &frame_listener, term); wl_callback_add_listener(term->window->frame_callback, &frame_listener, term);
@ -2191,7 +2191,7 @@ grid_render(struct terminal *term)
static void static void
render_search_box(struct terminal *term) render_search_box(struct terminal *term)
{ {
assert(term->window->search_sub_surface != NULL); xassert(term->window->search_sub_surface != NULL);
/* /*
* We treat the search box pretty much like a row of cells. That * We treat the search box pretty much like a row of cells. That
@ -2237,7 +2237,7 @@ render_search_box(struct terminal *term)
const size_t total_cells = wcswidth(text, text_len); const size_t total_cells = wcswidth(text, text_len);
const size_t wanted_visible_cells = max(20, total_cells); const size_t wanted_visible_cells = max(20, total_cells);
assert(term->scale >= 1); xassert(term->scale >= 1);
const int scale = term->scale; const int scale = term->scale;
const size_t margin = 3 * scale; const size_t margin = 3 * scale;
@ -2391,8 +2391,8 @@ render_search_box(struct terminal *term)
#endif #endif
{ {
/* Cursor *should* be in the visible area */ /* Cursor *should* be in the visible area */
assert(cell_idx >= glyph_offset); xassert(cell_idx >= glyph_offset);
assert(cell_idx <= glyph_offset + visible_cells); xassert(cell_idx <= glyph_offset + visible_cells);
draw_bar(term, buf->pix[0], font, &fg, x, y); draw_bar(term, buf->pix[0], font, &fg, x, y);
} }
} }
@ -2492,7 +2492,7 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da
{ {
struct terminal *term = data; struct terminal *term = data;
assert(term->window->frame_callback == wl_callback); xassert(term->window->frame_callback == wl_callback);
wl_callback_destroy(wl_callback); wl_callback_destroy(wl_callback);
term->window->frame_callback = NULL; term->window->frame_callback = NULL;
@ -2567,7 +2567,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
if (term->window->use_csd == CSD_YES) { if (term->window->use_csd == CSD_YES) {
/* Take CSD title bar into account */ /* Take CSD title bar into account */
assert(!term->window->is_fullscreen); xassert(!term->window->is_fullscreen);
height -= term->conf->csd.title_height; height -= term->conf->csd.title_height;
} }
@ -2591,8 +2591,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
if (height % scale) if (height % scale)
height += scale - height % scale; height += scale - height % scale;
assert(width % scale == 0); xassert(width % scale == 0);
assert(height % scale == 0); xassert(height % scale == 0);
break; break;
} }
} }
@ -2639,8 +2639,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
const int new_normal_grid_rows = 1 << (32 - __builtin_clz(new_rows + scrollback_lines - 1)); const int new_normal_grid_rows = 1 << (32 - __builtin_clz(new_rows + scrollback_lines - 1));
const int new_alt_grid_rows = 1 << (32 - __builtin_clz(new_rows)); const int new_alt_grid_rows = 1 << (32 - __builtin_clz(new_rows));
assert(new_cols >= 1); xassert(new_cols >= 1);
assert(new_rows >= 1); xassert(new_rows >= 1);
/* Margins */ /* Margins */
const int grid_width = new_cols * term->cell_width; const int grid_width = new_cols * term->cell_width;
@ -2658,10 +2658,10 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
term->margins.right = total_x_pad - term->margins.left; term->margins.right = total_x_pad - term->margins.left;
term->margins.bottom = total_y_pad - term->margins.top; term->margins.bottom = total_y_pad - term->margins.top;
assert(term->margins.left >= pad_x); xassert(term->margins.left >= pad_x);
assert(term->margins.right >= pad_x); xassert(term->margins.right >= pad_x);
assert(term->margins.top >= pad_y); xassert(term->margins.top >= pad_y);
assert(term->margins.bottom >= pad_y); xassert(term->margins.bottom >= pad_y);
if (new_cols == old_cols && new_rows == old_rows) { if (new_cols == old_cols && new_rows == old_rows) {
LOG_DBG("grid layout unaffected; skipping reflow"); LOG_DBG("grid layout unaffected; skipping reflow");
@ -2786,7 +2786,7 @@ render_xcursor_update(struct seat *seat)
if (!seat->mouse_focus) if (!seat->mouse_focus)
return; return;
assert(seat->pointer.xcursor != NULL); xassert(seat->pointer.xcursor != NULL);
if (seat->pointer.xcursor == XCURSOR_HIDDEN) { if (seat->pointer.xcursor == XCURSOR_HIDDEN) {
/* Hide cursor */ /* Hide cursor */
@ -2819,7 +2819,7 @@ render_xcursor_update(struct seat *seat)
wl_surface_set_buffer_scale(seat->pointer.surface, scale); wl_surface_set_buffer_scale(seat->pointer.surface, scale);
assert(seat->pointer.xcursor_callback == NULL); xassert(seat->pointer.xcursor_callback == NULL);
seat->pointer.xcursor_callback = wl_surface_frame(seat->pointer.surface); seat->pointer.xcursor_callback = wl_surface_frame(seat->pointer.surface);
wl_callback_add_listener(seat->pointer.xcursor_callback, &xcursor_listener, seat); wl_callback_add_listener(seat->pointer.xcursor_callback, &xcursor_listener, seat);
@ -2831,7 +2831,7 @@ xcursor_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_
{ {
struct seat *seat = data; struct seat *seat = data;
assert(seat->pointer.xcursor_callback == wl_callback); xassert(seat->pointer.xcursor_callback == wl_callback);
wl_callback_destroy(wl_callback); wl_callback_destroy(wl_callback);
seat->pointer.xcursor_callback = NULL; seat->pointer.xcursor_callback = NULL;

View file

@ -52,7 +52,7 @@ ensure_view_is_allocated(struct terminal *term, int new_view)
#if defined(_DEBUG) #if defined(_DEBUG)
for (size_t r = 0; r < term->rows; r++) for (size_t r = 0; r < term->rows; r++)
assert(term->grid->rows[(new_view + r) & (term->grid->num_rows - 1)] != NULL); xassert(term->grid->rows[(new_view + r) & (term->grid->num_rows - 1)] != NULL);
#endif #endif
return new_view; return new_view;
@ -197,7 +197,7 @@ search_update_selection(struct terminal *term,
#if defined(_DEBUG) #if defined(_DEBUG)
/* Verify all to-be-visible rows have been allocated */ /* Verify all to-be-visible rows have been allocated */
for (int r = 0; r < term->rows; r++) for (int r = 0; r < term->rows; r++)
assert(term->grid->rows[(new_view + r) & (term->grid->num_rows - 1)] != NULL); xassert(term->grid->rows[(new_view + r) & (term->grid->num_rows - 1)] != NULL);
#endif #endif
/* Update view */ /* Update view */
@ -220,7 +220,7 @@ search_update_selection(struct terminal *term,
while (selection_row < 0) while (selection_row < 0)
selection_row += term->grid->num_rows; selection_row += term->grid->num_rows;
assert(selection_row >= 0 && xassert(selection_row >= 0 &&
selection_row < term->grid->num_rows); selection_row < term->grid->num_rows);
selection_start( selection_start(
term, start_col, selection_row, SELECTION_CHAR_WISE, false); term, start_col, selection_row, SELECTION_CHAR_WISE, false);
@ -232,7 +232,7 @@ search_update_selection(struct terminal *term,
while (selection_row < 0) while (selection_row < 0)
selection_row += term->grid->num_rows; selection_row += term->grid->num_rows;
assert(selection_row >= 0 && xassert(selection_row >= 0 &&
selection_row < term->grid->num_rows); selection_row < term->grid->num_rows);
selection_update(term, end_col, selection_row); selection_update(term, end_col, selection_row);
} }
@ -255,7 +255,7 @@ search_find_next(struct terminal *term)
int start_col = term->search.match.col; int start_col = term->search.match.col;
size_t len = term->search.match_len; size_t len = term->search.match_len;
assert((len == 0 && start_row == -1 && start_col == -1) || xassert((len == 0 && start_row == -1 && start_col == -1) ||
(len > 0 && start_row >= 0 && start_col >= 0)); (len > 0 && start_row >= 0 && start_col >= 0));
if (len == 0) { if (len == 0) {
@ -365,7 +365,7 @@ search_add_chars(struct terminal *term, const char *src, size_t count)
if (!search_ensure_size(term, term->search.len + wchars)) if (!search_ensure_size(term, term->search.len + wchars))
return; return;
assert(term->search.len + wchars < term->search.sz); xassert(term->search.len + wchars < term->search.sz);
memmove(&term->search.buf[term->search.cursor + wchars], memmove(&term->search.buf[term->search.cursor + wchars],
&term->search.buf[term->search.cursor], &term->search.buf[term->search.cursor],
@ -386,8 +386,8 @@ search_match_to_end_of_word(struct terminal *term, bool spaces_only)
if (term->search.match_len == 0) if (term->search.match_len == 0)
return; return;
assert(term->search.match.row != -1); xassert(term->search.match.row != -1);
assert(term->search.match.col != -1); xassert(term->search.match.col != -1);
int end_row = term->search.match.row; int end_row = term->search.match.row;
int end_col = term->search.match.col; int end_col = term->search.match.col;
@ -466,7 +466,7 @@ distance_next_word(const struct terminal *term)
break; break;
} }
assert(cursor == term->search.len || iswspace(term->search.buf[cursor - 1])); xassert(cursor == term->search.len || iswspace(term->search.buf[cursor - 1]));
/* Now skip past whitespace, so that we end up at the beginning of /* Now skip past whitespace, so that we end up at the beginning of
* the next word */ * the next word */
@ -475,7 +475,7 @@ distance_next_word(const struct terminal *term)
break; break;
} }
assert(cursor == term->search.len || !iswspace(term->search.buf[cursor - 1])); xassert(cursor == term->search.len || !iswspace(term->search.buf[cursor - 1]));
if (cursor < term->search.len && !iswspace(term->search.buf[cursor])) if (cursor < term->search.len && !iswspace(term->search.buf[cursor]))
cursor--; cursor--;
@ -494,7 +494,7 @@ distance_prev_word(const struct terminal *term)
break; break;
} }
assert(cursor == 0 || !iswspace(term->search.buf[cursor])); xassert(cursor == 0 || !iswspace(term->search.buf[cursor]));
/* Now eat non-whitespace. This is the word we're skipping past */ /* Now eat non-whitespace. This is the word we're skipping past */
while (cursor > 0) { while (cursor > 0) {
@ -502,7 +502,7 @@ distance_prev_word(const struct terminal *term)
break; break;
} }
assert(cursor == 0 || iswspace(term->search.buf[cursor])); xassert(cursor == 0 || iswspace(term->search.buf[cursor]));
if (cursor > 0 && iswspace(term->search.buf[cursor])) if (cursor > 0 && iswspace(term->search.buf[cursor]))
cursor++; cursor++;
@ -593,7 +593,7 @@ execute_binding(struct seat *seat, struct terminal *term,
case BIND_ACTION_SEARCH_EDIT_LEFT_WORD: { case BIND_ACTION_SEARCH_EDIT_LEFT_WORD: {
size_t diff = distance_prev_word(term); size_t diff = distance_prev_word(term);
term->search.cursor -= diff; term->search.cursor -= diff;
assert(term->search.cursor <= term->search.len); xassert(term->search.cursor <= term->search.len);
return false; return false;
} }
@ -605,7 +605,7 @@ execute_binding(struct seat *seat, struct terminal *term,
case BIND_ACTION_SEARCH_EDIT_RIGHT_WORD: { case BIND_ACTION_SEARCH_EDIT_RIGHT_WORD: {
size_t diff = distance_next_word(term); size_t diff = distance_next_word(term);
term->search.cursor += diff; term->search.cursor += diff;
assert(term->search.cursor <= term->search.len); xassert(term->search.cursor <= term->search.len);
return false; return false;
} }
@ -683,11 +683,11 @@ execute_binding(struct seat *seat, struct terminal *term,
return false; return false;
case BIND_ACTION_SEARCH_COUNT: case BIND_ACTION_SEARCH_COUNT:
assert(false); xassert(false);
return false; return false;
} }
assert(false); xassert(false);
return false; return false;
} }

View file

@ -53,7 +53,7 @@ selection_on_rows(const struct terminal *term, int row_start, int row_end)
if (term->selection.end.row < 0) if (term->selection.end.row < 0)
return false; return false;
assert(term->selection.start.row != -1); xassert(term->selection.start.row != -1);
row_start += term->grid->offset; row_start += term->grid->offset;
row_end += term->grid->offset; row_end += term->grid->offset;
@ -142,7 +142,7 @@ foreach_selected_normal(
for (int r = start_row; r <= end_row; r++) { for (int r = start_row; r <= end_row; r++) {
size_t real_r = r & (term->grid->num_rows - 1); size_t real_r = r & (term->grid->num_rows - 1);
struct row *row = term->grid->rows[real_r]; struct row *row = term->grid->rows[real_r];
assert(row != NULL); xassert(row != NULL);
for (int c = start_col; for (int c = start_col;
c <= (r == end_row ? end_col : term->cols - 1); c <= (r == end_row ? end_col : term->cols - 1);
@ -178,7 +178,7 @@ foreach_selected_block(
for (int r = top_left.row; r <= bottom_right.row; r++) { for (int r = top_left.row; r <= bottom_right.row; r++) {
size_t real_r = r & (term->grid->num_rows - 1); size_t real_r = r & (term->grid->num_rows - 1);
struct row *row = term->grid->rows[real_r]; struct row *row = term->grid->rows[real_r];
assert(row != NULL); xassert(row != NULL);
for (int c = top_left.col; c <= bottom_right.col; c++) { for (int c = top_left.col; c <= bottom_right.col; c++) {
if (!cb(term, row, &row->cells[c], c, data)) if (!cb(term, row, &row->cells[c], c, data))
@ -205,11 +205,11 @@ foreach_selected(
return; return;
case SELECTION_NONE: case SELECTION_NONE:
assert(false); xassert(false);
return; return;
} }
assert(false); xassert(false);
} }
static bool static bool
@ -246,7 +246,7 @@ find_word_boundary_left(struct terminal *term, struct coord *pos,
wchar_t c = r->cells[pos->col].wc; wchar_t c = r->cells[pos->col].wc;
while (c == CELL_MULT_COL_SPACER) { while (c == CELL_MULT_COL_SPACER) {
assert(pos->col > 0); xassert(pos->col > 0);
if (pos->col == 0) if (pos->col == 0)
return; return;
pos->col--; pos->col--;
@ -280,7 +280,7 @@ find_word_boundary_left(struct terminal *term, struct coord *pos,
c = row->cells[next_col].wc; c = row->cells[next_col].wc;
while (c == CELL_MULT_COL_SPACER) { while (c == CELL_MULT_COL_SPACER) {
assert(next_col > 0); xassert(next_col > 0);
if (--next_col < 0) if (--next_col < 0)
return; return;
c = row->cells[next_col].wc; c = row->cells[next_col].wc;
@ -318,7 +318,7 @@ find_word_boundary_right(struct terminal *term, struct coord *pos,
wchar_t c = r->cells[pos->col].wc; wchar_t c = r->cells[pos->col].wc;
while (c == CELL_MULT_COL_SPACER) { while (c == CELL_MULT_COL_SPACER) {
assert(pos->col > 0); xassert(pos->col > 0);
if (pos->col == 0) if (pos->col == 0)
return; return;
pos->col--; pos->col--;
@ -436,7 +436,7 @@ selection_start(struct terminal *term, int col, int row,
break; break;
case SELECTION_NONE: case SELECTION_NONE:
assert(false); xassert(false);
break; break;
} }
@ -470,7 +470,7 @@ premark_selected(struct terminal *term, struct row *row, struct cell *cell,
int col, void *data) int col, void *data)
{ {
struct mark_context *ctx = data; struct mark_context *ctx = data;
assert(ctx != NULL); xassert(ctx != NULL);
if (ctx->last_row != row) { if (ctx->last_row != row) {
ctx->last_row = row; ctx->last_row = row;
@ -494,7 +494,7 @@ mark_selected(struct terminal *term, struct row *row, struct cell *cell,
int col, void *data) int col, void *data)
{ {
struct mark_context *ctx = data; struct mark_context *ctx = data;
assert(ctx != NULL); xassert(ctx != NULL);
if (ctx->last_row != row) { if (ctx->last_row != row) {
ctx->last_row = row; ctx->last_row = row;
@ -523,9 +523,9 @@ mark_selected(struct terminal *term, struct row *row, struct cell *cell,
static void static void
selection_modify(struct terminal *term, struct coord start, struct coord end) selection_modify(struct terminal *term, struct coord start, struct coord end)
{ {
assert(term->selection.start.row != -1); xassert(term->selection.start.row != -1);
assert(start.row != -1 && start.col != -1); xassert(start.row != -1 && start.col != -1);
assert(end.row != -1 && end.col != -1); xassert(end.row != -1 && end.col != -1);
struct mark_context ctx = {0}; struct mark_context ctx = {0};
@ -569,7 +569,7 @@ set_pivot_point_for_block_and_char_wise(struct terminal *term,
break; break;
/* Multi-column chars dont cross rows */ /* Multi-column chars dont cross rows */
assert(pivot_start->col > 0); xassert(pivot_start->col > 0);
if (pivot_start->col == 0) if (pivot_start->col == 0)
break; break;
@ -619,9 +619,9 @@ set_pivot_point_for_block_and_char_wise(struct terminal *term,
} }
} }
assert(term->grid->rows[pivot_start->row & (term->grid->num_rows - 1)]-> xassert(term->grid->rows[pivot_start->row & (term->grid->num_rows - 1)]->
cells[pivot_start->col].wc != CELL_MULT_COL_SPACER); cells[pivot_start->col].wc != CELL_MULT_COL_SPACER);
assert(term->grid->rows[pivot_end->row & (term->grid->num_rows - 1)]-> xassert(term->grid->rows[pivot_end->row & (term->grid->num_rows - 1)]->
cells[pivot_end->col].wc != CELL_MULT_COL_SPACER); cells[pivot_end->col].wc != CELL_MULT_COL_SPACER);
} }
@ -639,7 +639,7 @@ selection_update(struct terminal *term, int col, int row)
term->selection.end.row, term->selection.end.col, term->selection.end.row, term->selection.end.col,
row, col); row, col);
assert(term->grid->view + row != -1); xassert(term->grid->view + row != -1);
struct coord new_start = term->selection.start; struct coord new_start = term->selection.start;
struct coord new_end = {col, term->grid->view + row}; struct coord new_end = {col, term->grid->view + row};
@ -686,7 +686,7 @@ selection_update(struct terminal *term, int col, int row)
} }
if (new_direction == SELECTION_LEFT) { if (new_direction == SELECTION_LEFT) {
assert(pivot_end->row >= 0); xassert(pivot_end->row >= 0);
new_start = *pivot_end; new_start = *pivot_end;
} else } else
new_start = *pivot_start; new_start = *pivot_start;
@ -738,7 +738,7 @@ selection_update(struct terminal *term, int col, int row)
break; break;
case SELECTION_NONE: case SELECTION_NONE:
assert(false); xassert(false);
break; break;
} }
@ -797,7 +797,7 @@ selection_extend_normal(struct terminal *term, int col, int row,
end = tmp; end = tmp;
} }
assert(start->row < end->row || start->col < end->col); xassert(start->row < end->row || start->col < end->col);
struct coord new_start, new_end; struct coord new_start, new_end;
enum selection_direction direction; enum selection_direction direction;
@ -840,12 +840,12 @@ selection_extend_normal(struct terminal *term, int col, int row,
switch (term->selection.kind) { switch (term->selection.kind) {
case SELECTION_CHAR_WISE: case SELECTION_CHAR_WISE:
assert(new_kind == SELECTION_CHAR_WISE); xassert(new_kind == SELECTION_CHAR_WISE);
set_pivot_point_for_block_and_char_wise(term, new_start, direction); set_pivot_point_for_block_and_char_wise(term, new_start, direction);
break; break;
case SELECTION_WORD_WISE: { case SELECTION_WORD_WISE: {
assert(new_kind == SELECTION_CHAR_WISE || xassert(new_kind == SELECTION_CHAR_WISE ||
new_kind == SELECTION_WORD_WISE); new_kind == SELECTION_WORD_WISE);
struct coord pivot_start = {new_start.col, new_start.row - term->grid->view}; struct coord pivot_start = {new_start.col, new_start.row - term->grid->view};
@ -862,7 +862,7 @@ selection_extend_normal(struct terminal *term, int col, int row,
} }
case SELECTION_LINE_WISE: case SELECTION_LINE_WISE:
assert(new_kind == SELECTION_CHAR_WISE || xassert(new_kind == SELECTION_CHAR_WISE ||
new_kind == SELECTION_LINE_WISE); new_kind == SELECTION_LINE_WISE);
term->selection.pivot.start = (struct coord){0, new_start.row}; term->selection.pivot.start = (struct coord){0, new_start.row};
@ -871,7 +871,7 @@ selection_extend_normal(struct terminal *term, int col, int row,
case SELECTION_BLOCK: case SELECTION_BLOCK:
case SELECTION_NONE: case SELECTION_NONE:
assert(false); xassert(false);
break; break;
} }
@ -973,7 +973,7 @@ selection_extend(struct seat *seat, struct terminal *term,
switch (term->selection.kind) { switch (term->selection.kind) {
case SELECTION_NONE: case SELECTION_NONE:
assert(false); xassert(false);
return; return;
case SELECTION_CHAR_WISE: case SELECTION_CHAR_WISE:
@ -1004,8 +1004,8 @@ selection_finalize(struct seat *seat, struct terminal *term, uint32_t serial)
if (term->selection.start.row < 0 || term->selection.end.row < 0) if (term->selection.start.row < 0 || term->selection.end.row < 0)
return; return;
assert(term->selection.start.row != -1); xassert(term->selection.start.row != -1);
assert(term->selection.end.row != -1); xassert(term->selection.end.row != -1);
if (term->selection.start.row > term->selection.end.row || if (term->selection.start.row > term->selection.end.row ||
(term->selection.start.row == term->selection.end.row && (term->selection.start.row == term->selection.end.row &&
@ -1016,7 +1016,7 @@ selection_finalize(struct seat *seat, struct terminal *term, uint32_t serial)
term->selection.end = tmp; term->selection.end = tmp;
} }
assert(term->selection.start.row <= term->selection.end.row); xassert(term->selection.start.row <= term->selection.end.row);
selection_to_primary(seat, term, serial); selection_to_primary(seat, term, serial);
} }
@ -1066,7 +1066,7 @@ selection_clipboard_unset(struct seat *seat)
return; return;
/* Kill previous data source */ /* Kill previous data source */
assert(clipboard->serial != 0); xassert(clipboard->serial != 0);
wl_data_device_set_selection(seat->data_device, NULL, clipboard->serial); wl_data_device_set_selection(seat->data_device, NULL, clipboard->serial);
wl_data_source_destroy(clipboard->data_source); wl_data_source_destroy(clipboard->data_source);
@ -1085,7 +1085,7 @@ selection_primary_unset(struct seat *seat)
if (primary->data_source == NULL) if (primary->data_source == NULL)
return; return;
assert(primary->serial != 0); xassert(primary->serial != 0);
zwp_primary_selection_device_v1_set_selection( zwp_primary_selection_device_v1_set_selection(
seat->primary_selection_device, NULL, primary->serial); seat->primary_selection_device, NULL, primary->serial);
zwp_primary_selection_source_v1_destroy(primary->data_source); zwp_primary_selection_source_v1_destroy(primary->data_source);
@ -1141,7 +1141,7 @@ void
selection_start_scroll_timer(struct terminal *term, int interval_ns, selection_start_scroll_timer(struct terminal *term, int interval_ns,
enum selection_scroll_direction direction, int col) enum selection_scroll_direction direction, int col)
{ {
assert(direction != SELECTION_SCROLL_NOT); xassert(direction != SELECTION_SCROLL_NOT);
if (!term->selection.ongoing) if (!term->selection.ongoing)
return; return;
@ -1191,7 +1191,7 @@ void
selection_stop_scroll_timer(struct terminal *term) selection_stop_scroll_timer(struct terminal *term)
{ {
if (term->selection.auto_scroll.fd < 0) { if (term->selection.auto_scroll.fd < 0) {
assert(term->selection.auto_scroll.direction == SELECTION_SCROLL_NOT); xassert(term->selection.auto_scroll.direction == SELECTION_SCROLL_NOT);
return; return;
} }
@ -1294,7 +1294,7 @@ send(void *data, struct wl_data_source *wl_data_source, const char *mime_type,
struct seat *seat = data; struct seat *seat = data;
const struct wl_clipboard *clipboard = &seat->clipboard; const struct wl_clipboard *clipboard = &seat->clipboard;
assert(clipboard->text != NULL); xassert(clipboard->text != NULL);
send_clipboard_or_primary(seat, fd, clipboard->text, "clipboard"); send_clipboard_or_primary(seat, fd, clipboard->text, "clipboard");
} }
@ -1303,7 +1303,7 @@ cancelled(void *data, struct wl_data_source *wl_data_source)
{ {
struct seat *seat = data; struct seat *seat = data;
struct wl_clipboard *clipboard = &seat->clipboard; struct wl_clipboard *clipboard = &seat->clipboard;
assert(clipboard->data_source == wl_data_source); xassert(clipboard->data_source == wl_data_source);
wl_data_source_destroy(clipboard->data_source); wl_data_source_destroy(clipboard->data_source);
clipboard->data_source = NULL; clipboard->data_source = NULL;
@ -1349,7 +1349,7 @@ primary_send(void *data,
struct seat *seat = data; struct seat *seat = data;
const struct wl_primary *primary = &seat->primary; const struct wl_primary *primary = &seat->primary;
assert(primary->text != NULL); xassert(primary->text != NULL);
send_clipboard_or_primary(seat, fd, primary->text, "primary"); send_clipboard_or_primary(seat, fd, primary->text, "primary");
} }
@ -1380,7 +1380,7 @@ text_to_clipboard(struct seat *seat, struct terminal *term, char *text, uint32_t
if (clipboard->data_source != NULL) { if (clipboard->data_source != NULL) {
/* Kill previous data source */ /* Kill previous data source */
assert(clipboard->serial != 0); xassert(clipboard->serial != 0);
wl_data_device_set_selection(seat->data_device, NULL, clipboard->serial); wl_data_device_set_selection(seat->data_device, NULL, clipboard->serial);
wl_data_source_destroy(clipboard->data_source); wl_data_source_destroy(clipboard->data_source);
free(clipboard->text); free(clipboard->text);
@ -1411,7 +1411,7 @@ text_to_clipboard(struct seat *seat, struct terminal *term, char *text, uint32_t
wl_data_device_set_selection(seat->data_device, clipboard->data_source, serial); wl_data_device_set_selection(seat->data_device, clipboard->data_source, serial);
/* Needed when sending the selection to other client */ /* Needed when sending the selection to other client */
assert(serial != 0); xassert(serial != 0);
clipboard->serial = serial; clipboard->serial = serial;
return true; return true;
} }
@ -1467,7 +1467,7 @@ fdm_receive_timeout(struct fdm *fdm, int fd, int events, void *data)
if (events & EPOLLHUP) if (events & EPOLLHUP)
return false; return false;
assert(events & EPOLLIN); xassert(events & EPOLLIN);
uint64_t expire_count; uint64_t expire_count;
ssize_t ret = read(fd, &expire_count, sizeof(expire_count)); ssize_t ret = read(fd, &expire_count, sizeof(expire_count));
@ -1600,7 +1600,7 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
if (p[i] == '\r' && p[i + 1] == '\n') { if (p[i] == '\r' && p[i + 1] == '\n') {
ctx->decoder(ctx, p, i); ctx->decoder(ctx, p, i);
assert(i + 1 <= left); xassert(i + 1 <= left);
p += i + 1; p += i + 1;
left -= i + 1; left -= i + 1;
goto again; goto again;
@ -1718,7 +1718,7 @@ static void
receive_offer(char *data, size_t size, void *user) receive_offer(char *data, size_t size, void *user)
{ {
struct terminal *term = user; struct terminal *term = user;
assert(term->is_sending_paste_data); xassert(term->is_sending_paste_data);
term_paste_data_to_slave(term, data, size); term_paste_data_to_slave(term, data, size);
} }
static void static void
@ -1768,7 +1768,7 @@ text_to_primary(struct seat *seat, struct terminal *term, char *text, uint32_t s
if (seat->primary.data_source != NULL) { if (seat->primary.data_source != NULL) {
/* Kill previous data source */ /* Kill previous data source */
assert(primary->serial != 0); xassert(primary->serial != 0);
zwp_primary_selection_device_v1_set_selection( zwp_primary_selection_device_v1_set_selection(
seat->primary_selection_device, NULL, primary->serial); seat->primary_selection_device, NULL, primary->serial);
zwp_primary_selection_source_v1_destroy(primary->data_source); zwp_primary_selection_source_v1_destroy(primary->data_source);
@ -2046,10 +2046,10 @@ enter(void *data, struct wl_data_device *wl_data_device, uint32_t serial,
struct seat *seat = data; struct seat *seat = data;
struct wayland *wayl = seat->wayl; struct wayland *wayl = seat->wayl;
assert(offer == seat->clipboard.data_offer); xassert(offer == seat->clipboard.data_offer);
/* Remember _which_ terminal the current DnD offer is targeting */ /* Remember _which_ terminal the current DnD offer is targeting */
assert(seat->clipboard.window == NULL); xassert(seat->clipboard.window == NULL);
tll_foreach(wayl->terms, it) { tll_foreach(wayl->terms, it) {
if (term_surface_kind(it->item, surface) == TERM_SURF_GRID && if (term_surface_kind(it->item, surface) == TERM_SURF_GRID &&
!it->item->is_sending_paste_data) !it->item->is_sending_paste_data)
@ -2113,7 +2113,7 @@ drop(void *data, struct wl_data_device *wl_data_device)
{ {
struct seat *seat = data; struct seat *seat = data;
assert(seat->clipboard.window != NULL); xassert(seat->clipboard.window != NULL);
struct terminal *term = seat->clipboard.window->term; struct terminal *term = seat->clipboard.window->term;
struct wl_clipboard *clipboard = &seat->clipboard; struct wl_clipboard *clipboard = &seat->clipboard;
@ -2167,7 +2167,7 @@ selection(void *data, struct wl_data_device *wl_data_device,
if (offer == NULL) if (offer == NULL)
data_offer_reset(&seat->clipboard); data_offer_reset(&seat->clipboard);
else else
assert(offer == seat->clipboard.data_offer); xassert(offer == seat->clipboard.data_offer);
} }
const struct wl_data_device_listener data_device_listener = { const struct wl_data_device_listener data_device_listener = {
@ -2227,7 +2227,7 @@ primary_selection(void *data,
if (offer == NULL) if (offer == NULL)
primary_offer_reset(&seat->primary); primary_offer_reset(&seat->primary);
else else
assert(seat->primary.data_offer == offer); xassert(seat->primary.data_offer == offer);
} }
const struct zwp_primary_selection_device_v1_listener primary_selection_device_listener = { const struct zwp_primary_selection_device_v1_listener primary_selection_device_listener = {

View file

@ -123,7 +123,7 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
if (events & EPOLLHUP) if (events & EPOLLHUP)
goto shutdown; goto shutdown;
assert(events & EPOLLIN); xassert(events & EPOLLIN);
if (client->term != NULL) { if (client->term != NULL) {
uint8_t dummy[128]; uint8_t dummy[128];
@ -186,9 +186,9 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
/* All initialization data received - time to instantiate a terminal! */ /* All initialization data received - time to instantiate a terminal! */
assert(client->term == NULL); xassert(client->term == NULL);
assert(client->buffer.data != NULL); xassert(client->buffer.data != NULL);
assert(client->buffer.left == 0); xassert(client->buffer.left == 0);
/* /*
* Parse the received buffer, verifying lengths etc * Parse the received buffer, verifying lengths etc

48
shm.c
View file

@ -121,8 +121,8 @@ buffer_release(void *data, struct wl_buffer *wl_buffer)
{ {
struct buffer *buffer = data; struct buffer *buffer = data;
LOG_DBG("release: cookie=%lx (buf=%p)", buffer->cookie, (void *)buffer); LOG_DBG("release: cookie=%lx (buf=%p)", buffer->cookie, (void *)buffer);
assert(buffer->wl_buf == wl_buffer); xassert(buffer->wl_buf == wl_buffer);
assert(buffer->busy); xassert(buffer->busy);
buffer->busy = false; buffer->busy = false;
} }
@ -143,17 +143,17 @@ page_size(void)
size = (size_t)n; size = (size_t)n;
} }
} }
assert(size > 0); xassert(size > 0);
return size; return size;
} }
static bool static bool
instantiate_offset(struct wl_shm *shm, struct buffer *buf, off_t new_offset) instantiate_offset(struct wl_shm *shm, struct buffer *buf, off_t new_offset)
{ {
assert(buf->fd >= 0); xassert(buf->fd >= 0);
assert(buf->mmapped == NULL); xassert(buf->mmapped == NULL);
assert(buf->wl_buf == NULL); xassert(buf->wl_buf == NULL);
assert(buf->pix == NULL); xassert(buf->pix == NULL);
void *mmapped = MAP_FAILED; void *mmapped = MAP_FAILED;
struct wl_buffer *wl_buf = NULL; struct wl_buffer *wl_buf = NULL;
@ -211,7 +211,7 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie,
if (!it->item.purge) if (!it->item.purge)
continue; continue;
assert(!it->item.busy); xassert(!it->item.busy);
LOG_DBG("cookie=%lx: purging buffer %p (width=%d, height=%d): %zu KB", LOG_DBG("cookie=%lx: purging buffer %p (width=%d, height=%d): %zu KB",
cookie, (void *)&it->item, it->item.width, it->item.height, cookie, (void *)&it->item, it->item.width, it->item.height,
@ -234,7 +234,7 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie,
cookie, (void *)&it->item); cookie, (void *)&it->item);
it->item.busy = true; it->item.busy = true;
it->item.purge = false; it->item.purge = false;
assert(it->item.pix_instances == pix_instances); xassert(it->item.pix_instances == pix_instances);
return &it->item; return &it->item;
} }
} }
@ -414,7 +414,7 @@ wrap_buffer(struct wl_shm *shm, struct buffer *buf, off_t new_offset)
/* We don't allow overlapping offsets */ /* We don't allow overlapping offsets */
off_t UNUSED diff = off_t UNUSED diff =
new_offset < buf->offset ? buf->offset - new_offset : new_offset - buf->offset; new_offset < buf->offset ? buf->offset - new_offset : new_offset - buf->offset;
assert(diff > buf->size); xassert(diff > buf->size);
memcpy((uint8_t *)buf->real_mmapped + new_offset, buf->mmapped, buf->size); memcpy((uint8_t *)buf->real_mmapped + new_offset, buf->mmapped, buf->size);
@ -448,17 +448,17 @@ shm_scroll_forward(struct wl_shm *shm, struct buffer *buf, int rows,
int top_margin, int top_keep_rows, int top_margin, int top_keep_rows,
int bottom_margin, int bottom_keep_rows) int bottom_margin, int bottom_keep_rows)
{ {
assert(can_punch_hole); xassert(can_punch_hole);
assert(buf->busy); xassert(buf->busy);
assert(buf->pix); xassert(buf->pix);
assert(buf->wl_buf); xassert(buf->wl_buf);
assert(buf->fd >= 0); xassert(buf->fd >= 0);
LOG_DBG("scrolling %d rows (%d bytes)", rows, rows * buf->stride); LOG_DBG("scrolling %d rows (%d bytes)", rows, rows * buf->stride);
const off_t diff = rows * buf->stride; const off_t diff = rows * buf->stride;
assert(rows > 0); xassert(rows > 0);
assert(diff < buf->size); xassert(diff < buf->size);
if (buf->offset + diff + buf->size > max_pool_size) { if (buf->offset + diff + buf->size > max_pool_size) {
LOG_DBG("memfd offset wrap around"); LOG_DBG("memfd offset wrap around");
@ -467,8 +467,8 @@ shm_scroll_forward(struct wl_shm *shm, struct buffer *buf, int rows,
} }
off_t new_offset = buf->offset + diff; off_t new_offset = buf->offset + diff;
assert(new_offset > buf->offset); xassert(new_offset > buf->offset);
assert(new_offset + buf->size <= max_pool_size); xassert(new_offset + buf->size <= max_pool_size);
#if TIME_SCROLL #if TIME_SCROLL
struct timeval time1; struct timeval time1;
@ -552,7 +552,7 @@ shm_scroll_reverse(struct wl_shm *shm, struct buffer *buf, int rows,
int top_margin, int top_keep_rows, int top_margin, int top_keep_rows,
int bottom_margin, int bottom_keep_rows) int bottom_margin, int bottom_keep_rows)
{ {
assert(rows > 0); xassert(rows > 0);
const off_t diff = rows * buf->stride; const off_t diff = rows * buf->stride;
if (diff > buf->offset) { if (diff > buf->offset) {
@ -562,8 +562,8 @@ shm_scroll_reverse(struct wl_shm *shm, struct buffer *buf, int rows,
} }
off_t new_offset = buf->offset - diff; off_t new_offset = buf->offset - diff;
assert(new_offset < buf->offset); xassert(new_offset < buf->offset);
assert(new_offset <= max_pool_size); xassert(new_offset <= max_pool_size);
#if TIME_SCROLL #if TIME_SCROLL
struct timeval time0; struct timeval time0;
@ -649,7 +649,7 @@ shm_scroll(struct wl_shm *shm, struct buffer *buf, int rows,
if (!shm_can_scroll(buf)) if (!shm_can_scroll(buf))
return false; return false;
assert(rows != 0); xassert(rows != 0);
return rows > 0 return rows > 0
? shm_scroll_forward(shm, buf, rows, top_margin, top_keep_rows, bottom_margin, bottom_keep_rows) ? shm_scroll_forward(shm, buf, rows, top_margin, top_keep_rows, bottom_margin, bottom_keep_rows)
: shm_scroll_reverse(shm, buf, -rows, top_margin, top_keep_rows, bottom_margin, bottom_keep_rows); : shm_scroll_reverse(shm, buf, -rows, top_margin, top_keep_rows, bottom_margin, bottom_keep_rows);
@ -665,7 +665,7 @@ shm_purge(struct wl_shm *shm, unsigned long cookie)
if (it->item.cookie != cookie) if (it->item.cookie != cookie)
continue; continue;
assert(!it->item.busy); xassert(!it->item.busy);
buffer_destroy(&it->item); buffer_destroy(&it->item);
tll_remove(buffers, it); tll_remove(buffers, it);

70
sixel.c
View file

@ -31,8 +31,8 @@ color_with_alpha(const struct terminal *term, uint32_t color)
void void
sixel_init(struct terminal *term) sixel_init(struct terminal *term)
{ {
assert(term->sixel.image.data == NULL); xassert(term->sixel.image.data == NULL);
assert(term->sixel.palette_size <= SIXEL_MAX_COLORS); xassert(term->sixel.palette_size <= SIXEL_MAX_COLORS);
term->sixel.state = SIXEL_DECSIXEL; term->sixel.state = SIXEL_DECSIXEL;
term->sixel.pos = (struct coord){0, 0}; term->sixel.pos = (struct coord){0, 0};
@ -142,13 +142,13 @@ verify_list_order(const struct terminal *term)
int col = it->item.pos.col; int col = it->item.pos.col;
int col_count = it->item.cols; int col_count = it->item.cols;
assert(row <= prev_row); xassert(row <= prev_row);
if (row == prev_row) { if (row == prev_row) {
/* Allowed to be on the same row only if their columns /* Allowed to be on the same row only if their columns
* don't overlap */ * don't overlap */
assert(col + col_count <= prev_col || xassert(col + col_count <= prev_col ||
prev_col + prev_col_count <= col); prev_col + prev_col_count <= col);
} }
@ -172,11 +172,11 @@ verify_no_wraparound_crossover(const struct terminal *term)
tll_foreach(term->grid->sixel_images, it) { tll_foreach(term->grid->sixel_images, it) {
const struct sixel *six = &it->item; const struct sixel *six = &it->item;
assert(six->pos.row >= 0); xassert(six->pos.row >= 0);
assert(six->pos.row < term->grid->num_rows); xassert(six->pos.row < term->grid->num_rows);
int end = (six->pos.row + six->rows - 1) & (term->grid->num_rows - 1); int end = (six->pos.row + six->rows - 1) & (term->grid->num_rows - 1);
assert(end >= six->pos.row); xassert(end >= six->pos.row);
} }
#endif #endif
} }
@ -198,7 +198,7 @@ verify_scrollback_consistency(const struct terminal *term)
int row_no = rebase_row(term, six->pos.row + i); int row_no = rebase_row(term, six->pos.row + i);
if (last_row != -1) if (last_row != -1)
assert(last_row < row_no); xassert(last_row < row_no);
last_row = row_no; last_row = row_no;
} }
@ -235,7 +235,7 @@ verify_no_overlap(const struct terminal *term)
pixman_region32_init(&intersection); pixman_region32_init(&intersection);
pixman_region32_intersect(&intersection, &rect1, &rect2); pixman_region32_intersect(&intersection, &rect1, &rect2);
assert(!pixman_region32_not_empty(&intersection)); xassert(!pixman_region32_not_empty(&intersection));
pixman_region32_fini(&intersection); pixman_region32_fini(&intersection);
pixman_region32_fini(&rect2); pixman_region32_fini(&rect2);
@ -315,7 +315,7 @@ sixel_scroll_down(struct terminal *term, int rows)
if (likely(tll_length(term->grid->sixel_images) == 0)) if (likely(tll_length(term->grid->sixel_images) == 0))
return; return;
assert(term->grid->num_rows >= rows); xassert(term->grid->num_rows >= rows);
tll_foreach(term->grid->sixel_images, it) { tll_foreach(term->grid->sixel_images, it) {
struct sixel *six = &it->item; struct sixel *six = &it->item;
@ -351,7 +351,7 @@ sixel_overwrite(struct terminal *term, struct sixel *six,
pixman_region32_t intersection; pixman_region32_t intersection;
pixman_region32_init(&intersection); pixman_region32_init(&intersection);
pixman_region32_intersect(&intersection, &six_rect, &overwrite_rect); pixman_region32_intersect(&intersection, &six_rect, &overwrite_rect);
assert(pixman_region32_not_empty(&intersection)); xassert(pixman_region32_not_empty(&intersection));
pixman_region32_fini(&intersection); pixman_region32_fini(&intersection);
#endif #endif
@ -369,14 +369,14 @@ sixel_overwrite(struct terminal *term, struct sixel *six,
LOG_DBG("box #%d: x1=%d, y1=%d, x2=%d, y2=%d", i, LOG_DBG("box #%d: x1=%d, y1=%d, x2=%d, y2=%d", i,
boxes[i].x1, boxes[i].y1, boxes[i].x2, boxes[i].y2); boxes[i].x1, boxes[i].y1, boxes[i].x2, boxes[i].y2);
assert(boxes[i].x1 % term->cell_width == 0); xassert(boxes[i].x1 % term->cell_width == 0);
assert(boxes[i].y1 % term->cell_height == 0); xassert(boxes[i].y1 % term->cell_height == 0);
/* New image's position, in cells */ /* New image's position, in cells */
const int new_col = boxes[i].x1 / term->cell_width; const int new_col = boxes[i].x1 / term->cell_width;
const int new_row = boxes[i].y1 / term->cell_height; const int new_row = boxes[i].y1 / term->cell_height;
assert(new_row < term->grid->num_rows); xassert(new_row < term->grid->num_rows);
/* New image's width and height, in pixels */ /* New image's width and height, in pixels */
const int new_width = boxes[i].x2 - boxes[i].x1; const int new_width = boxes[i].x2 - boxes[i].x1;
@ -414,7 +414,7 @@ sixel_overwrite(struct terminal *term, struct sixel *six,
#if defined(_DEBUG) #if defined(_DEBUG)
/* Assert we don't cross the scrollback wrap-around */ /* Assert we don't cross the scrollback wrap-around */
const int new_end = new_six.pos.row + new_six.rows - 1; const int new_end = new_six.pos.row + new_six.rows - 1;
assert(new_end < term->grid->num_rows); xassert(new_end < term->grid->num_rows);
#endif #endif
sixel_insert(term, new_six); sixel_insert(term, new_six);
@ -439,7 +439,7 @@ _sixel_overwrite_by_rectangle(
const int end = row + height - 1; const int end = row + height - 1;
/* We should never generate scrollback wrapping sixels */ /* We should never generate scrollback wrapping sixels */
assert(end < term->grid->num_rows); xassert(end < term->grid->num_rows);
const int scrollback_rel_start = rebase_row(term, start); const int scrollback_rel_start = rebase_row(term, start);
@ -453,7 +453,7 @@ _sixel_overwrite_by_rectangle(
const int six_scrollback_rel_end = rebase_row(term, six_end); const int six_scrollback_rel_end = rebase_row(term, six_end);
/* We should never generate scrollback wrapping sixels */ /* We should never generate scrollback wrapping sixels */
assert(six_end < term->grid->num_rows); xassert(six_end < term->grid->num_rows);
if (six_scrollback_rel_end < scrollback_rel_start) { if (six_scrollback_rel_end < scrollback_rel_start) {
/* All remaining sixels are *before* our rectangle */ /* All remaining sixels are *before* our rectangle */
@ -485,7 +485,7 @@ _sixel_overwrite_by_rectangle(
(col <= col_end && col + width - 1 >= col_end) || (col <= col_end && col + width - 1 >= col_end) ||
(col >= col_start && col + width - 1 <= col_end)) (col >= col_start && col + width - 1 <= col_end))
{ {
assert(!would_have_breaked); xassert(!would_have_breaked);
struct sixel to_be_erased = *six; struct sixel to_be_erased = *six;
tll_remove(term->grid->sixel_images, it); tll_remove(term->grid->sixel_images, it);
@ -493,9 +493,9 @@ _sixel_overwrite_by_rectangle(
sixel_overwrite(term, &to_be_erased, start, col, height, width); sixel_overwrite(term, &to_be_erased, start, col, height, width);
sixel_erase(term, &to_be_erased); sixel_erase(term, &to_be_erased);
} else } else
assert(!collides); xassert(!collides);
} else } else
assert(!collides); xassert(!collides);
#if defined(_DEBUG) #if defined(_DEBUG)
pixman_region32_fini(&intersection); pixman_region32_fini(&intersection);
@ -521,7 +521,7 @@ sixel_overwrite_by_rectangle(
if (wraps) { if (wraps) {
int rows_to_wrap_around = term->grid->num_rows - start; int rows_to_wrap_around = term->grid->num_rows - start;
assert(height - rows_to_wrap_around > 0); xassert(height - rows_to_wrap_around > 0);
_sixel_overwrite_by_rectangle(term, start, col, rows_to_wrap_around, width); _sixel_overwrite_by_rectangle(term, start, col, rows_to_wrap_around, width);
_sixel_overwrite_by_rectangle(term, 0, col, height - rows_to_wrap_around, width); _sixel_overwrite_by_rectangle(term, 0, col, height - rows_to_wrap_around, width);
} else } else
@ -532,12 +532,12 @@ sixel_overwrite_by_rectangle(
void void
sixel_overwrite_by_row(struct terminal *term, int _row, int col, int width) sixel_overwrite_by_row(struct terminal *term, int _row, int col, int width)
{ {
assert(col >= 0); xassert(col >= 0);
assert(_row >= 0); xassert(_row >= 0);
assert(_row < term->rows); xassert(_row < term->rows);
assert(col >= 0); xassert(col >= 0);
assert(col < term->grid->num_cols); xassert(col < term->grid->num_cols);
if (likely(tll_length(term->grid->sixel_images) == 0)) if (likely(tll_length(term->grid->sixel_images) == 0))
return; return;
@ -554,7 +554,7 @@ sixel_overwrite_by_row(struct terminal *term, int _row, int col, int width)
const int six_end = (six_start + six->rows - 1) & (term->grid->num_rows - 1); const int six_end = (six_start + six->rows - 1) & (term->grid->num_rows - 1);
/* We should never generate scrollback wrapping sixels */ /* We should never generate scrollback wrapping sixels */
assert(six_end >= six_start); xassert(six_end >= six_start);
const int six_scrollback_rel_end = rebase_row(term, six_end); const int six_scrollback_rel_end = rebase_row(term, six_end);
@ -731,8 +731,8 @@ sixel_unhook(struct terminal *term)
.pos = (struct coord){start_col, cur_row}, .pos = (struct coord){start_col, cur_row},
}; };
assert(image.rows < term->grid->num_rows); xassert(image.rows < term->grid->num_rows);
assert(image.pos.row + image.rows - 1 < term->grid->num_rows); xassert(image.pos.row + image.rows - 1 < term->grid->num_rows);
LOG_DBG("generating %dx%d pixman image at %d-%d", LOG_DBG("generating %dx%d pixman image at %d-%d",
image.width, image.height, image.width, image.height,
@ -796,8 +796,8 @@ resize(struct terminal *term, int new_width, int new_height)
int alloc_new_width = new_width; int alloc_new_width = new_width;
int alloc_new_height = (new_height + 6 - 1) / 6 * 6; int alloc_new_height = (new_height + 6 - 1) / 6 * 6;
assert(alloc_new_height >= new_height); xassert(alloc_new_height >= new_height);
assert(alloc_new_height - new_height < 6); xassert(alloc_new_height - new_height < 6);
uint32_t *new_data = NULL; uint32_t *new_data = NULL;
@ -811,11 +811,11 @@ resize(struct terminal *term, int new_width, int new_height)
return false; return false;
} }
assert(new_height > old_height); xassert(new_height > old_height);
} else { } else {
/* Width (and thus stride) change - need to allocate a new buffer */ /* Width (and thus stride) change - need to allocate a new buffer */
assert(new_width > old_width); xassert(new_width > old_width);
new_data = xmalloc(alloc_new_width * alloc_new_height * sizeof(uint32_t)); new_data = xmalloc(alloc_new_width * alloc_new_height * sizeof(uint32_t));
/* Copy old rows, and initialize new columns to background color */ /* Copy old rows, and initialize new columns to background color */
@ -834,7 +834,7 @@ resize(struct terminal *term, int new_width, int new_height)
new_data[r * new_width + c] = color_with_alpha(term, term->colors.bg); new_data[r * new_width + c] = color_with_alpha(term, term->colors.bg);
} }
assert(new_data != NULL); xassert(new_data != NULL);
term->sixel.image.data = new_data; term->sixel.image.data = new_data;
term->sixel.image.width = new_width; term->sixel.image.width = new_width;
term->sixel.image.height = new_height; term->sixel.image.height = new_height;
@ -877,7 +877,7 @@ sixel_add(struct terminal *term, uint32_t color, uint8_t sixel)
} }
} }
assert(sixel == 0); xassert(sixel == 0);
term->sixel.pos.col++; term->sixel.pos.col++;
} }

View file

@ -90,7 +90,7 @@ emit_one_notification(int fd, const struct user_notification *notif)
break; break;
} }
assert(prefix != NULL); xassert(prefix != NULL);
if (write(fd, prefix, strlen(prefix)) < 0 || if (write(fd, prefix, strlen(prefix)) < 0 ||
write(fd, notif->text, strlen(notif->text)) < 0 || write(fd, notif->text, strlen(notif->text)) < 0 ||
@ -314,7 +314,7 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
setenv("SHELL", shell_argv[0], 1); setenv("SHELL", shell_argv[0], 1);
slave_exec(ptmx, shell_argv, fork_pipe[1], login_shell, notifications); slave_exec(ptmx, shell_argv, fork_pipe[1], login_shell, notifications);
assert(false); xassert(false);
break; break;
default: { default: {

View file

@ -41,7 +41,7 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
(void)!write(pipe_fds[1], &errno, sizeof(errno)); (void)!write(pipe_fds[1], &errno, sizeof(errno));
_exit(errno); _exit(errno);
} }
assert(false); xassert(false);
_exit(errno); _exit(errno);
} }

View file

@ -94,14 +94,14 @@ data_to_slave(struct terminal *term, const void *data, size_t len,
} }
/* Shouldn't get here */ /* Shouldn't get here */
assert(false); xassert(false);
return false; return false;
} }
bool bool
term_paste_data_to_slave(struct terminal *term, const void *data, size_t len) term_paste_data_to_slave(struct terminal *term, const void *data, size_t len)
{ {
assert(term->is_sending_paste_data); xassert(term->is_sending_paste_data);
if (term->ptmx < 0) { if (term->ptmx < 0) {
/* We're probably in "hold" */ /* We're probably in "hold" */
@ -150,7 +150,7 @@ fdm_ptmx_out(struct fdm *fdm, int fd, int events, void *data)
struct terminal *term = data; struct terminal *term = data;
/* If there is no queued data, then we shouldn't be in asynchronous mode */ /* If there is no queued data, then we shouldn't be in asynchronous mode */
assert(tll_length(term->ptmx_buffers) > 0 || xassert(tll_length(term->ptmx_buffers) > 0 ||
tll_length(term->ptmx_paste_buffers) > 0); tll_length(term->ptmx_paste_buffers) > 0);
/* Writes a single buffer, returns if not all of it could be written */ /* Writes a single buffer, returns if not all of it could be written */
@ -230,7 +230,7 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
const size_t max_iterations = 10; const size_t max_iterations = 10;
for (size_t i = 0; i < max_iterations && pollin && count == sizeof(buf); i++) { for (size_t i = 0; i < max_iterations && pollin && count == sizeof(buf); i++) {
assert(pollin); xassert(pollin);
count = read(term->ptmx, buf, sizeof(buf)); count = read(term->ptmx, buf, sizeof(buf));
if (count < 0) { if (count < 0) {
@ -291,9 +291,9 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
last = now; last = now;
#endif #endif
assert(lower_ns < 1000000000); xassert(lower_ns < 1000000000);
assert(upper_ns < 1000000000); xassert(upper_ns < 1000000000);
assert(upper_ns > lower_ns); xassert(upper_ns > lower_ns);
timerfd_settime( timerfd_settime(
term->delayed_render_timer.lower_fd, 0, term->delayed_render_timer.lower_fd, 0,
@ -621,7 +621,7 @@ static bool
term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4]) term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
{ {
for (size_t i = 0; i < 4; i++) { for (size_t i = 0; i < 4; i++) {
assert(fonts[i] != NULL); xassert(fonts[i] != NULL);
fcft_destroy(term->fonts[i]); fcft_destroy(term->fonts[i]);
term->fonts[i] = fonts[i]; term->fonts[i] = fonts[i];
@ -710,7 +710,7 @@ get_font_dpi(const struct terminal *term)
/* Use highest DPI from outputs we're mapped on */ /* Use highest DPI from outputs we're mapped on */
double dpi = 0.0; double dpi = 0.0;
assert(term->window != NULL); xassert(term->window != NULL);
tll_foreach(term->window->on_outputs, it) { tll_foreach(term->window->on_outputs, it) {
if (it->item->dpi > dpi) if (it->item->dpi > dpi)
dpi = it->item->dpi; dpi = it->item->dpi;
@ -738,7 +738,7 @@ get_font_scale(const struct terminal *term)
/* Same as get_font_dpi(), but returns output scale factor instead */ /* Same as get_font_dpi(), but returns output scale factor instead */
int scale = 0; int scale = 0;
assert(term->window != NULL); xassert(term->window != NULL);
tll_foreach(term->window->on_outputs, it) { tll_foreach(term->window->on_outputs, it) {
if (it->item->scale > scale) if (it->item->scale > scale)
scale = it->item->scale; scale = it->item->scale;
@ -1267,7 +1267,7 @@ term_window_configured(struct terminal *term)
{ {
/* Enable ptmx FDM callback */ /* Enable ptmx FDM callback */
if (!term->is_shutting_down) { if (!term->is_shutting_down) {
assert(term->window->is_configured); xassert(term->window->is_configured);
fdm_add(term->fdm, term->ptmx, EPOLLIN, &fdm_ptmx, term); fdm_add(term->fdm, term->ptmx, EPOLLIN, &fdm_ptmx, term);
} }
} }
@ -1325,7 +1325,7 @@ term_shutdown(struct terminal *term)
*/ */
term_cursor_blink_update(term); term_cursor_blink_update(term);
assert(term->cursor_blink.fd < 0); xassert(term->cursor_blink.fd < 0);
fdm_del(term->fdm, term->selection.auto_scroll.fd); fdm_del(term->fdm, term->selection.auto_scroll.fd);
fdm_del(term->fdm, term->render.app_sync_updates.timer_fd); fdm_del(term->fdm, term->render.app_sync_updates.timer_fd);
@ -1405,7 +1405,7 @@ term_destroy(struct terminal *term)
wayl_win_destroy(term->window); wayl_win_destroy(term->window);
mtx_lock(&term->render.workers.lock); mtx_lock(&term->render.workers.lock);
assert(tll_length(term->render.workers.queue) == 0); xassert(tll_length(term->render.workers.queue) == 0);
/* Count livinig threads - we may get here when only some of the /* Count livinig threads - we may get here when only some of the
* threads have been successfully started */ * threads have been successfully started */
@ -1463,7 +1463,7 @@ term_destroy(struct terminal *term)
mtx_destroy(&term->render.workers.lock); mtx_destroy(&term->render.workers.lock);
sem_destroy(&term->render.workers.start); sem_destroy(&term->render.workers.start);
sem_destroy(&term->render.workers.done); sem_destroy(&term->render.workers.done);
assert(tll_length(term->render.workers.queue) == 0); xassert(tll_length(term->render.workers.queue) == 0);
tll_free(term->render.workers.queue); tll_free(term->render.workers.queue);
tll_foreach(term->ptmx_buffers, it) tll_foreach(term->ptmx_buffers, it)
@ -1522,7 +1522,7 @@ term_destroy(struct terminal *term)
break; break;
if (r == -1) { if (r == -1) {
assert(errno == EINTR); xassert(errno == EINTR);
if (alarm_raised) { if (alarm_raised) {
LOG_DBG("slave hasn't died yet, sending: %s (%d)", LOG_DBG("slave hasn't died yet, sending: %s (%d)",
@ -1570,8 +1570,8 @@ term_destroy(struct terminal *term)
static inline void static inline void
erase_cell_range(struct terminal *term, struct row *row, int start, int end) erase_cell_range(struct terminal *term, struct row *row, int start, int end)
{ {
assert(start < term->cols); xassert(start < term->cols);
assert(end < term->cols); xassert(end < term->cols);
row->dirty = true; row->dirty = true;
@ -1807,7 +1807,7 @@ term_font_subpixel_changed(struct terminal *term)
void void
term_damage_rows(struct terminal *term, int start, int end) term_damage_rows(struct terminal *term, int start, int end)
{ {
assert(start <= end); xassert(start <= end);
for (int r = start; r <= end; r++) { for (int r = start; r <= end; r++) {
struct row *row = grid_row(term->grid, r); struct row *row = grid_row(term->grid, r);
row->dirty = true; row->dirty = true;
@ -1819,7 +1819,7 @@ term_damage_rows(struct terminal *term, int start, int end)
void void
term_damage_rows_in_view(struct terminal *term, int start, int end) term_damage_rows_in_view(struct terminal *term, int start, int end)
{ {
assert(start <= end); xassert(start <= end);
for (int r = start; r <= end; r++) { for (int r = start; r <= end; r++) {
struct row *row = grid_row_in_view(term->grid, r); struct row *row = grid_row_in_view(term->grid, r);
row->dirty = true; row->dirty = true;
@ -1879,8 +1879,8 @@ term_damage_scroll(struct terminal *term, enum damage_type damage_type,
void void
term_erase(struct terminal *term, const struct coord *start, const struct coord *end) term_erase(struct terminal *term, const struct coord *start, const struct coord *end)
{ {
assert(start->row <= end->row); xassert(start->row <= end->row);
assert(start->col <= end->col || start->row < end->row); xassert(start->col <= end->col || start->row < end->row);
if (start->row == end->row) { if (start->row == end->row) {
struct row *row = grid_row(term->grid, start->row); struct row *row = grid_row(term->grid, start->row);
@ -1889,7 +1889,7 @@ term_erase(struct terminal *term, const struct coord *start, const struct coord
return; return;
} }
assert(end->row > start->row); xassert(end->row > start->row);
erase_cell_range( erase_cell_range(
term, grid_row(term->grid, start->row), start->col, term->cols - 1); term, grid_row(term->grid, start->row), start->col, term->cols - 1);
@ -1915,15 +1915,15 @@ term_row_rel_to_abs(const struct terminal *term, int row)
return min(row + term->scroll_region.start, term->scroll_region.end - 1); return min(row + term->scroll_region.start, term->scroll_region.end - 1);
} }
assert(false); xassert(false);
return -1; return -1;
} }
void void
term_cursor_to(struct terminal *term, int row, int col) term_cursor_to(struct terminal *term, int row, int col)
{ {
assert(row < term->rows); xassert(row < term->rows);
assert(col < term->cols); xassert(col < term->cols);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
@ -1942,7 +1942,7 @@ term_cursor_home(struct terminal *term)
void void
term_cursor_left(struct terminal *term, int count) term_cursor_left(struct terminal *term, int count)
{ {
assert(count >= 0); xassert(count >= 0);
int new_col = term->grid->cursor.point.col - count; int new_col = term->grid->cursor.point.col - count;
/* Reverse wrap */ /* Reverse wrap */
@ -1957,7 +1957,7 @@ term_cursor_left(struct terminal *term, int count)
/* New column number */ /* New column number */
new_col = term->cols - ((abs(new_col) - 1) % term->cols + 1); new_col = term->cols - ((abs(new_col) - 1) % term->cols + 1);
assert(new_col >= 0 && new_col < term->cols); xassert(new_col >= 0 && new_col < term->cols);
/* Don't back up past the scroll region */ /* Don't back up past the scroll region */
/* TODO: should this be allowed? */ /* TODO: should this be allowed? */
@ -1978,7 +1978,7 @@ term_cursor_left(struct terminal *term, int count)
new_col = 0; new_col = 0;
} }
assert(new_col >= 0); xassert(new_col >= 0);
term->grid->cursor.point.col = new_col; term->grid->cursor.point.col = new_col;
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
} }
@ -1988,7 +1988,7 @@ term_cursor_right(struct terminal *term, int count)
{ {
int move_amount = min(term->cols - term->grid->cursor.point.col - 1, count); int move_amount = min(term->cols - term->grid->cursor.point.col - 1, count);
term->grid->cursor.point.col += move_amount; term->grid->cursor.point.col += move_amount;
assert(term->grid->cursor.point.col < term->cols); xassert(term->grid->cursor.point.col < term->cols);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
} }
@ -1996,7 +1996,7 @@ void
term_cursor_up(struct terminal *term, int count) term_cursor_up(struct terminal *term, int count)
{ {
int top = term->origin == ORIGIN_ABSOLUTE ? 0 : term->scroll_region.start; int top = term->origin == ORIGIN_ABSOLUTE ? 0 : term->scroll_region.start;
assert(term->grid->cursor.point.row >= top); xassert(term->grid->cursor.point.row >= top);
int move_amount = min(term->grid->cursor.point.row - top, count); int move_amount = min(term->grid->cursor.point.row - top, count);
term_cursor_to(term, term->grid->cursor.point.row - move_amount, term->grid->cursor.point.col); term_cursor_to(term, term->grid->cursor.point.row - move_amount, term->grid->cursor.point.col);
@ -2006,7 +2006,7 @@ void
term_cursor_down(struct terminal *term, int count) term_cursor_down(struct terminal *term, int count)
{ {
int bottom = term->origin == ORIGIN_ABSOLUTE ? term->rows : term->scroll_region.end; int bottom = term->origin == ORIGIN_ABSOLUTE ? term->rows : term->scroll_region.end;
assert(bottom >= term->grid->cursor.point.row); xassert(bottom >= term->grid->cursor.point.row);
int move_amount = min(bottom - term->grid->cursor.point.row - 1, count); int move_amount = min(bottom - term->grid->cursor.point.row - 1, count);
term_cursor_to(term, term->grid->cursor.point.row + move_amount, term->grid->cursor.point.col); term_cursor_to(term, term->grid->cursor.point.row + move_amount, term->grid->cursor.point.col);
@ -2094,7 +2094,7 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows
rows, region.start, region.end); rows, region.start, region.end);
/* Verify scroll amount has been clamped */ /* Verify scroll amount has been clamped */
assert(rows <= region.end - region.start); xassert(rows <= region.end - region.start);
/* Cancel selections that cannot be scrolled */ /* Cancel selections that cannot be scrolled */
if (unlikely(term->selection.end.row >= 0)) { if (unlikely(term->selection.end.row >= 0)) {
@ -2139,7 +2139,7 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows
#if defined(_DEBUG) #if defined(_DEBUG)
for (int r = 0; r < term->rows; r++) for (int r = 0; r < term->rows; r++)
assert(grid_row(term->grid, r) != NULL); xassert(grid_row(term->grid, r) != NULL);
#endif #endif
} }
@ -2157,7 +2157,7 @@ term_scroll_reverse_partial(struct terminal *term,
rows, region.start, region.end); rows, region.start, region.end);
/* Verify scroll amount has been clamped */ /* Verify scroll amount has been clamped */
assert(rows <= region.end - region.start); xassert(rows <= region.end - region.start);
/* Cancel selections that cannot be scrolled */ /* Cancel selections that cannot be scrolled */
if (unlikely(term->selection.end.row >= 0)) { if (unlikely(term->selection.end.row >= 0)) {
@ -2182,8 +2182,8 @@ term_scroll_reverse_partial(struct terminal *term,
term->grid->offset += term->grid->num_rows; term->grid->offset += term->grid->num_rows;
term->grid->offset &= term->grid->num_rows - 1; term->grid->offset &= term->grid->num_rows - 1;
assert(term->grid->offset >= 0); xassert(term->grid->offset >= 0);
assert(term->grid->offset < term->grid->num_rows); xassert(term->grid->offset < term->grid->num_rows);
if (view_follows) { if (view_follows) {
selection_view_up(term, term->grid->offset); selection_view_up(term, term->grid->offset);
@ -2207,7 +2207,7 @@ term_scroll_reverse_partial(struct terminal *term,
#if defined(_DEBUG) #if defined(_DEBUG)
for (int r = 0; r < term->rows; r++) for (int r = 0; r < term->rows; r++)
assert(grid_row(term->grid, r) != NULL); xassert(grid_row(term->grid, r) != NULL);
#endif #endif
} }
@ -2470,7 +2470,7 @@ term_mouse_down(struct terminal *term, int button, int row, int col,
case MOUSE_X10: case MOUSE_X10:
/* Never enabled */ /* Never enabled */
assert(false && "unimplemented"); xassert(false && "unimplemented");
break; break;
} }
} }
@ -2512,7 +2512,7 @@ term_mouse_up(struct terminal *term, int button, int row, int col,
case MOUSE_X10: case MOUSE_X10:
/* Never enabled */ /* Never enabled */
assert(false && "unimplemented"); xassert(false && "unimplemented");
break; break;
} }
} }
@ -2559,7 +2559,7 @@ term_mouse_motion(struct terminal *term, int button, int row, int col,
case MOUSE_X10: case MOUSE_X10:
/* Never enabled */ /* Never enabled */
assert(false && "unimplemented"); xassert(false && "unimplemented");
break; break;
} }
} }
@ -2720,7 +2720,7 @@ print_insert(struct terminal *term, int width)
if (likely(!term->insert_mode)) if (likely(!term->insert_mode))
return; return;
assert(width > 0); xassert(width > 0);
struct row *row = term->grid->cur_row; struct row *row = term->grid->cur_row;
const size_t move_count = max(0, term->cols - term->grid->cursor.point.col - width); const size_t move_count = max(0, term->cols - term->grid->cursor.point.col - width);
@ -2749,7 +2749,7 @@ print_spacer(struct terminal *term, int col)
void void
term_print(struct terminal *term, wchar_t wc, int width) term_print(struct terminal *term, wchar_t wc, int width)
{ {
assert(width > 0); xassert(width > 0);
print_linewrap(term); print_linewrap(term);
print_insert(term, width); print_insert(term, width);
@ -2788,7 +2788,7 @@ term_print(struct terminal *term, wchar_t wc, int width)
/* Advance cursor */ /* Advance cursor */
if (term->grid->cursor.point.col < term->cols - 1) { if (term->grid->cursor.point.col < term->cols - 1) {
term->grid->cursor.point.col++; term->grid->cursor.point.col++;
assert(!term->grid->cursor.lcf); xassert(!term->grid->cursor.lcf);
} else } else
term->grid->cursor.lcf = true; term->grid->cursor.lcf = true;
} }
@ -2837,7 +2837,7 @@ rows_to_text(const struct terminal *term, int start, int end,
r = (r + 1) & (term->grid->num_rows - 1)) r = (r + 1) & (term->grid->num_rows - 1))
{ {
const struct row *row = term->grid->rows[r]; const struct row *row = term->grid->rows[r];
assert(row != NULL); xassert(row != NULL);
for (int c = 0; c < term->cols; c++) for (int c = 0; c < term->cols; c++)
if (!extract_one(term, row, &row->cells[c], c, ctx)) if (!extract_one(term, row, &row->cells[c], c, ctx))

22
vt.c
View file

@ -89,7 +89,7 @@ esc_as_string(struct terminal *term, uint8_t final)
c += snprintf(&msg[c], sizeof(msg) - c, "%c", value); c += snprintf(&msg[c], sizeof(msg) - c, "%c", value);
} }
assert(term->vt.params.idx == 0); xassert(term->vt.params.idx == 0);
snprintf(&msg[c], sizeof(msg) - c, "%c", final); snprintf(&msg[c], sizeof(msg) - c, "%c", final);
return msg; return msg;
@ -156,7 +156,7 @@ action_execute(struct terminal *term, uint8_t c)
break; break;
} }
} }
assert(new_col >= term->grid->cursor.point.col); xassert(new_col >= term->grid->cursor.point.col);
/* According to the specification, HT _should_ cancel LCF. But /* According to the specification, HT _should_ cancel LCF. But
* XTerm, and nearly all other emulators, don't. So we follow * XTerm, and nearly all other emulators, don't. So we follow
@ -238,7 +238,7 @@ action_print(struct terminal *term, uint8_t c)
L'', L'', L'', L'π', L'', L'£', L'·', /* x - ~ */ L'', L'', L'', L'π', L'', L'£', L'·', /* x - ~ */
}; };
assert(wcwidth(c) == 1); xassert(wcwidth(c) == 1);
if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) && if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) &&
c >= 0x60 && c <= 0x7e) c >= 0x60 && c <= 0x7e)
@ -259,7 +259,7 @@ action_param(struct terminal *term, uint8_t c)
term->vt.params.idx = 1; term->vt.params.idx = 1;
} }
assert(term->vt.params.idx > 0); xassert(term->vt.params.idx > 0);
const size_t max_params const size_t max_params
= sizeof(term->vt.params.v) / sizeof(term->vt.params.v[0]); = sizeof(term->vt.params.v) / sizeof(term->vt.params.v[0]);
@ -309,9 +309,9 @@ action_param(struct terminal *term, uint8_t c)
#if defined(_DEBUG) #if defined(_DEBUG)
/* The rest of the code assumes 'idx' *never* points outside the array */ /* The rest of the code assumes 'idx' *never* points outside the array */
assert(term->vt.params.idx <= max_params); xassert(term->vt.params.idx <= max_params);
for (size_t i = 0; i < term->vt.params.idx; i++) for (size_t i = 0; i < term->vt.params.idx; i++)
assert(term->vt.params.v[i].sub.idx <= max_sub_params); xassert(term->vt.params.v[i].sub.idx <= max_sub_params);
#endif #endif
return; return;
@ -453,7 +453,7 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
')' ? 1 : ')' ? 1 :
'*' ? 2 : '*' ? 2 :
'+' ? 3 : -1; '+' ? 3 : -1;
assert(idx != -1); xassert(idx != -1);
term->charsets.set[idx] = CHARSET_GRAPHIC; term->charsets.set[idx] = CHARSET_GRAPHIC;
break; break;
} }
@ -465,7 +465,7 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
')' ? 1 : ')' ? 1 :
'*' ? 2 : '*' ? 2 :
'+' ? 3 : -1; '+' ? 3 : -1;
assert(idx != -1); xassert(idx != -1);
term->charsets.set[idx] = CHARSET_ASCII; term->charsets.set[idx] = CHARSET_ASCII;
break; break;
@ -570,7 +570,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
while (row->cells[base_col].wc == CELL_MULT_COL_SPACER && base_col > 0) while (row->cells[base_col].wc == CELL_MULT_COL_SPACER && base_col > 0)
base_col--; base_col--;
assert(base_col >= 0 && base_col < term->cols); xassert(base_col >= 0 && base_col < term->cols);
wchar_t base = row->cells[base_col].wc; wchar_t base = row->cells[base_col].wc;
const struct composed *composed = const struct composed *composed =
@ -632,7 +632,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
size_t wanted_count = composed != NULL ? composed->count + 1 : 1; size_t wanted_count = composed != NULL ? composed->count + 1 : 1;
if (wanted_count > ALEN(composed->combining)) { if (wanted_count > ALEN(composed->combining)) {
assert(composed != NULL); xassert(composed != NULL);
#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG #if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG
LOG_WARN("combining character overflow:"); LOG_WARN("combining character overflow:");
@ -645,7 +645,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
wanted_count--; wanted_count--;
} }
assert(wanted_count <= ALEN(composed->combining)); xassert(wanted_count <= ALEN(composed->combining));
/* Look for existing combining chain */ /* Look for existing combining chain */
for (size_t i = 0; i < term->composed_count; i++) { for (size_t i = 0; i < term->composed_count; i++) {

View file

@ -37,11 +37,11 @@ static void
csd_instantiate(struct wl_window *win) csd_instantiate(struct wl_window *win)
{ {
struct wayland *wayl = win->term->wl; struct wayland *wayl = win->term->wl;
assert(wayl != NULL); xassert(wayl != NULL);
for (size_t i = 0; i < ALEN(win->csd.surface); i++) { for (size_t i = 0; i < ALEN(win->csd.surface); i++) {
assert(win->csd.surface[i] == NULL); xassert(win->csd.surface[i] == NULL);
assert(win->csd.sub_surface[i] == NULL); xassert(win->csd.sub_surface[i] == NULL);
win->csd.surface[i] = wl_compositor_create_surface(wayl->compositor); win->csd.surface[i] = wl_compositor_create_surface(wayl->compositor);
@ -231,7 +231,7 @@ seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
enum wl_seat_capability caps) enum wl_seat_capability caps)
{ {
struct seat *seat = data; struct seat *seat = data;
assert(seat->wl_seat == wl_seat); xassert(seat->wl_seat == wl_seat);
LOG_DBG("%s: keyboard=%s, pointer=%s", seat->name, LOG_DBG("%s: keyboard=%s, pointer=%s", seat->name,
(caps & WL_SEAT_CAPABILITY_KEYBOARD) ? "yes" : "no", (caps & WL_SEAT_CAPABILITY_KEYBOARD) ? "yes" : "no",
@ -251,7 +251,7 @@ seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
if (caps & WL_SEAT_CAPABILITY_POINTER) { if (caps & WL_SEAT_CAPABILITY_POINTER) {
if (seat->wl_pointer == NULL) { if (seat->wl_pointer == NULL) {
assert(seat->pointer.surface == NULL); xassert(seat->pointer.surface == NULL);
seat->pointer.surface = wl_compositor_create_surface(seat->wayl->compositor); seat->pointer.surface = wl_compositor_create_surface(seat->wayl->compositor);
if (seat->pointer.surface == NULL) { if (seat->pointer.surface == NULL) {
@ -708,7 +708,7 @@ xdg_toplevel_decoration_configure(void *data,
{ {
struct wl_window *win = data; struct wl_window *win = data;
assert(win->term->conf->csd.preferred != CONF_CSD_PREFER_NONE); xassert(win->term->conf->csd.preferred != CONF_CSD_PREFER_NONE);
switch (mode) { switch (mode) {
case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE:
LOG_INFO("using CSD decorations"); LOG_INFO("using CSD decorations");
@ -1440,7 +1440,7 @@ wayl_reload_xcursor_theme(struct seat *seat, int new_scale)
} }
if (seat->pointer.theme != NULL) { if (seat->pointer.theme != NULL) {
assert(seat->pointer.scale != new_scale); xassert(seat->pointer.scale != new_scale);
wl_cursor_theme_destroy(seat->pointer.theme); wl_cursor_theme_destroy(seat->pointer.theme);
seat->pointer.theme = NULL; seat->pointer.theme = NULL;
seat->pointer.cursor = NULL; seat->pointer.cursor = NULL;
@ -1495,7 +1495,7 @@ wayl_flush(struct wayland *wayl)
/* Socket buffer is full - need to wait for it to become /* Socket buffer is full - need to wait for it to become
writeable again */ writeable again */
assert(errno == EAGAIN); xassert(errno == EAGAIN);
while (true) { while (true) {
struct pollfd fds[] = {{.fd = wayl->fd, .events = POLLOUT}}; struct pollfd fds[] = {{.fd = wayl->fd, .events = POLLOUT}};
@ -1513,7 +1513,7 @@ wayl_flush(struct wayland *wayl)
if (fds[0].revents & POLLHUP) if (fds[0].revents & POLLHUP)
return; return;
assert(fds[0].revents & POLLOUT); xassert(fds[0].revents & POLLOUT);
break; break;
} }
} }

View file

@ -28,7 +28,7 @@ xmalloc(size_t size)
void * void *
xcalloc(size_t nmemb, size_t size) xcalloc(size_t nmemb, size_t size)
{ {
assert(size != 0); xassert(size != 0);
return check_alloc(calloc(likely(nmemb) ? nmemb : 1, size)); return check_alloc(calloc(likely(nmemb) ? nmemb : 1, size));
} }

View file

@ -7,7 +7,7 @@
size_t size_t
xvsnprintf(char *buf, size_t n, const char *format, va_list ap) xvsnprintf(char *buf, size_t n, const char *format, va_list ap)
{ {
assert(n <= INT_MAX); xassert(n <= INT_MAX);
int len = vsnprintf(buf, n, format, ap); int len = vsnprintf(buf, n, format, ap);
/* /*
@ -19,8 +19,8 @@ xvsnprintf(char *buf, size_t n, const char *format, va_list ap)
* has been completely written if and only if the returned value * has been completely written if and only if the returned value
* is nonnegative and less than n." * is nonnegative and less than n."
*/ */
assert(len >= 0); xassert(len >= 0);
assert(len < (int)n); xassert(len < (int)n);
return (size_t)len; return (size_t)len;
} }