diff options
| author | Craig Barnes <craigbarnes@protonmail.com> | 2022-03-13 18:22:04 +0000 |
|---|---|---|
| committer | Craig Barnes <craigbarnes@protonmail.com> | 2022-03-13 18:22:04 +0000 |
| commit | 2a4e7fde8d63cc33595a156771c82e18afa77e64 (patch) | |
| tree | c772ad03640979d80b63e670cb2c4398426afa1b | |
| parent | input: get_current_modifiers(): don’t crash if seat has no keyboard (diff) | |
| parent | osc: grow OSC buffer exponentially instead of by fixed increments of 128 (diff) | |
Merge branch 'osc-buffer-growth'
| -rw-r--r-- | osc.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -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; |
