diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-03-19 19:22:59 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-03-21 19:40:50 +0000 |
| commit | 67a228bf4b8b826544c13dac561e4965750465d7 (patch) | |
| tree | 6d5ae500e51aaa575398b02484fcea2071cb159a | |
| parent | dcs: decrqss: use a custom put() handler (diff) | |
dcs: xtgettcap: use custom put() handler
Grow buffer exponentially, since XTGETTCAP requests can,
theoretically, be very large.
| -rw-r--r-- | dcs.c | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -16,17 +16,14 @@ ensure_size(struct terminal *term, size_t required_size) if (required_size <= term->vt.dcs.size) return true; - size_t new_size = (required_size + 127) / 128 * 128; - xassert(new_size > 0); - - uint8_t *new_data = realloc(term->vt.dcs.data, new_size); + uint8_t *new_data = realloc(term->vt.dcs.data, required_size); if (new_data == NULL) { LOG_ERRNO("failed to increase size of DCS buffer"); return false; } term->vt.dcs.data = new_data; - term->vt.dcs.size = new_size; + term->vt.dcs.size = required_size; return true; } @@ -181,6 +178,24 @@ out: } static void +xtgettcap_put(struct terminal *term, uint8_t c) +{ + struct vt *vt = &term->vt; + + /* Grow buffer expontentially */ + if (vt->dcs.idx >= vt->dcs.size) { + size_t new_size = vt->dcs.size * 2; + if (new_size == 0) + new_size = 128; + + if (!ensure_size(term, new_size)) + return; + } + + vt->dcs.data[vt->dcs.idx++] = c; +} + +static void xtgettcap_unhook(struct terminal *term) { size_t left = term->vt.dcs.idx; @@ -445,6 +460,7 @@ dcs_hook(struct terminal *term, uint8_t final) case '+': switch (final) { case 'q': /* XTGETTCAP */ + term->vt.dcs.put_handler = &xtgettcap_put; term->vt.dcs.unhook_handler = &xtgettcap_unhook; break; } |
