summaryrefslogtreecommitdiff
path: root/src/screen.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 12:29:35 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 12:29:35 +0300
commite47f9f20d68eda78a6621917a7e100ae333a1a53 (patch)
tree47552c95fc3e47d9379a31568eef1095d17709ab /src/screen.c
parent5f03033b0e211f9ed13e7a1351f9a8f9011ab665 (diff)
Reject invalid arguments instead of ignoring them
term_feed() returns bool and rejects a NULL terminal, a NULL buffer with a nonzero length, and any flag bit it does not know. Unknown bits are rejected now so that later flags can be added without changing what the old calls mean. term_new() returns NULL for a negative size component, columns above TERM_MAX_COLS, a negative scrollback, or a cursor style outside the enum. Zero still selects the default size and scrollback. It no longer clamps bad values silently. term_resize() rejects columns above TERM_MAX_COLS instead of clamping them, which matches how it already rejects a size below 1. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/screen.c')
-rw-r--r--src/screen.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/screen.c b/src/screen.c
index 87d6f2c..697e08a 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -808,12 +808,11 @@ void term_screen_set_alternate(struct term *t, bool enabled)
}
}
+/* The caller has checked that requested is not negative. */
static int scrollback_lines(int requested)
{
if (requested == 0)
return TERM_SCROLLBACK_DEFAULT;
- if (requested < 0)
- return 0;
return requested > 1000000 ? 1000000 : requested;
}
@@ -847,10 +846,12 @@ struct term *term_new(const struct term_options *opt)
static const struct term_options defaults;
if (!opt)
opt = &defaults;
- int cols = opt->size.x < 1 ? 80 : opt->size.x;
- int rows = opt->size.y < 1 ? 24 : opt->size.y;
- if (cols > TERM_MAX_COLS)
- cols = TERM_MAX_COLS;
+ if (opt->size.x < 0 || opt->size.y < 0 || opt->size.x > TERM_MAX_COLS)
+ return NULL;
+ if (opt->scrollback < 0 || (unsigned)opt->cursor_style > TERM_CURSOR_BAR)
+ return NULL;
+ int cols = opt->size.x == 0 ? 80 : opt->size.x;
+ int rows = opt->size.y == 0 ? 24 : opt->size.y;
static _Atomic uint64_t next_serial = 1;
struct term *t = calloc(1, sizeof(*t));
@@ -895,7 +896,7 @@ struct term *term_new(const struct term_options *opt)
t->cur_fg = TERM_COLOR_FG;
t->cur_bg = TERM_COLOR_BG;
t->cursor_visible = true;
- t->default_cursor_style = opt->cursor_style > TERM_CURSOR_BAR ? TERM_CURSOR_BLOCK : opt->cursor_style;
+ t->default_cursor_style = opt->cursor_style;
t->default_cursor_blink = !opt->cursor_steady;
t->cursor_style = t->default_cursor_style;
t->cursor_blink = t->default_cursor_blink;
@@ -1523,10 +1524,8 @@ bool term_resize(struct term *t, struct term_vector2i size)
return false;
int cols = size.x;
int rows = size.y;
- if (cols < 1 || rows < 1)
+ if (cols < 1 || rows < 1 || cols > TERM_MAX_COLS)
return false;
- if (cols > TERM_MAX_COLS)
- cols = TERM_MAX_COLS;
term_write_begin(t);
if (cols == t->cols && rows == t->rows) {
term_write_end(t);