Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
uname output: Linux westring 6.12.28 #1 SMP PREEMPT_DYNAMIC Fri May 9 16:58:50
CDT 2025 x86_64 AMD Ryzen 5 7600 6-Core Processor AuthenticAMD GNU/Linux
Machine Type: x86_64-pc-linux-gnu
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.
Repeat-By:
1. Enable vi line editing
2. Set PS1 to at be least 126 characters long
3. Hit Escape to get out of insert mode
4. Hit / to start a history search
Expected result: The / is displayed after the PS1 prompt
Actual result: Only the prompt is displayed
Fix:
diff --git c/lib/readline/display.c w/lib/readline/display.c
index edb525d3..5c5f58d8 100644
--- c/lib/readline/display.c
+++ w/lib/readline/display.c
@@ -3143,14 +3143,14 @@ rl_message (const char *format, ...)
#if defined (HAVE_VSNPRINTF)
bneed = vsnprintf (msg_buf, msg_bufsiz, format, args);
- if (bneed >= msg_bufsiz - 1)
+ if (bneed > msg_bufsiz - 1)
{
msg_bufsiz = bneed + 1;
msg_buf = xrealloc (msg_buf, msg_bufsiz);
va_end (args);
va_start (args, format);
- vsnprintf (msg_buf, msg_bufsiz - 1, format, args);
+ vsnprintf (msg_buf, msg_bufsiz, format, args);
}
#else
vsprintf (msg_buf, format, args);
--
Torgny Lyon