aboutsummaryrefslogtreecommitdiff
path: root/osc.c
diff options
context:
space:
mode:
authorCraig Barnes <craigbarnes@protonmail.com>2022-03-13 18:22:04 +0000
committerCraig Barnes <craigbarnes@protonmail.com>2022-03-13 18:22:04 +0000
commit2a4e7fde8d63cc33595a156771c82e18afa77e64 (patch)
treec772ad03640979d80b63e670cb2c4398426afa1b /osc.c
parentinput: get_current_modifiers(): don’t crash if seat has no keyboard (diff)
parentosc: grow OSC buffer exponentially instead of by fixed increments of 128 (diff)
Merge branch 'osc-buffer-growth'
Diffstat (limited to 'osc.c')
-rw-r--r--osc.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/osc.c b/osc.c
index 9c3b326a..94b6892c 100644
--- a/osc.c
+++ b/osc.c
@@ -902,11 +902,20 @@ osc_dispatch(struct terminal *term)
bool
osc_ensure_size(struct terminal *term, size_t required_size)
{
- if (required_size <= term->vt.osc.size)
+ if (likely(required_size <= term->vt.osc.size))
return true;
- size_t new_size = (required_size + 127) / 128 * 128;
- xassert(new_size > 0);
+ const size_t pow2_max = ~(SIZE_MAX >> 1);
+ if (unlikely(required_size > pow2_max)) {
+ LOG_ERR("required OSC buffer size (%zu) exceeds limit (%zu)",
+ required_size, pow2_max);
+ return false;
+ }
+
+ size_t new_size = max(term->vt.osc.size, 4096);
+ while (new_size < required_size) {
+ new_size <<= 1;
+ }
uint8_t *new_data = realloc(term->vt.osc.data, new_size);
if (new_data == NULL) {
@@ -914,6 +923,7 @@ osc_ensure_size(struct terminal *term, size_t required_size)
return false;
}
+ LOG_DBG("resized OSC buffer: %zu", new_size);
term->vt.osc.data = new_data;
term->vt.osc.size = new_size;
return true;