Re: Readline discards the last character of long messages
From:
Chet Ramey
Subject:
Re: Readline discards the last character of long messages
Date:
Mon, 14 Jul 2025 11:23:39 -0400
User-agent:
Mozilla Thunderbird
On 7/12/25 5:30 AM, Torgny Lyon wrote:
Bash Version: 5.3
Patch Level: 0
Release Status: maint
Description:
When formatting long messages that wont fit into its buffer,
readline will reallocate the buffer to be just as large as is
needed, but it will then not make use of the whole buffer for
the formatted message, resulting in the last character being
left out. Fixing the call to vsnprintf() alone would fix the
exhibited _behavior_.
However, readline also decides to perform the reallocation of
the buffer "too early". This explains why the bug is triggered
already when the prompt in the example below is only 126
characters. The 128 bytes of the buffer would be sufficient for
holding the 126 characters of the prompt, a '/', and a
terminating '\0', but readline is off by one and therefor
performs the reallocation and the faulty formatting even in this
case.
The attached patch fixes both these issues.
Thanks for the report and patch.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/