diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 12:29:35 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 12:29:35 +0300 |
| commit | e47f9f20d68eda78a6621917a7e100ae333a1a53 (patch) | |
| tree | 47552c95fc3e47d9379a31568eef1095d17709ab /src/text.c | |
| parent | 5f03033b0e211f9ed13e7a1351f9a8f9011ab665 (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/text.c')
| -rw-r--r-- | src/text.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -190,10 +190,11 @@ static inline bool try_text_run(struct term *t, const char *buf, size_t len, return wrote; } +/* The feed flags this build knows. term_feed() rejects any other bit. */ +#define TERM_FEED_KNOWN TERM_FEED_ONLCR + static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigned flags) { - if (!t || !buf || len == 0) - return; t->transport_newline = (flags & TERM_FEED_ONLCR) != 0; uint16_t cur_flags = term_current_flags(t); @@ -366,13 +367,16 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne } } -void term_feed(struct term *t, const char *buf, size_t len, unsigned flags) +bool term_feed(struct term *t, const char *buf, size_t len, unsigned flags) { - if (!t || !buf || len == 0) - return; + if (!t || (!buf && len > 0) || (flags & ~TERM_FEED_KNOWN)) + return false; + if (len == 0) + return true; term_write_begin(t); term_feed_inner(t, buf, len, flags); term_write_end(t); + return true; } void term_text_repeat(struct term *t, int count) |
