From fb87fc32f04be636e1e0fe8eea611a453ee2d3f0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Oct 2020 13:28:48 +0530 Subject: [PATCH] Fix a regression that caused a segfault when using scrollback_pager_history_size Fixes #3011 --- docs/changelog.rst | 3 +++ kitty/history.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index f70f95551..d1bff76a2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -10,6 +10,9 @@ To update |kitty|, :doc:`follow the instructions `. - hints kitten: Add an ``ip`` type for easy selection of IP addresses (:pull:`3009`) +- Fix a regression that caused a segfault when using + :opt:`scrollback_pager_history_size` and it gets full (:iss:`3011`) + - Fix update available notifications repeating (:pull:`3006`) diff --git a/kitty/history.c b/kitty/history.c index 2443d5184..48a06897b 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -78,8 +78,8 @@ free_pagerhist(HistoryBuf *self) { static inline bool pagerhist_extend(PagerHistoryBuf *ph, size_t minsz) { if (ph->buffer_size >= ph->max_sz) return false; - size_t newsz = ph->buffer_size + MAX(1024u * 1024u, minsz); - uint8_t *newbuf = PyMem_Malloc(MIN(ph->buffer_size + minsz, ph->max_sz)); + size_t newsz = MIN(ph->max_sz, ph->buffer_size + MAX(1024u * 1024u, minsz)); + uint8_t *newbuf = PyMem_Malloc(newsz); if (!newbuf) return false; size_t copied = MIN(ph->length, ph->buffer_size - ph->start); if (copied) memcpy(newbuf, ph->buffer + ph->start, copied);