5 Patch-ID: readline82-013
7 Bug-Reported-by: Grisha Levit <grishalevit@gmail.com>
8 Bug-Reference-ID: <CAMu=Brrv5qKY6LPfw8PxqNXNO8rNsZo0Fb=BcFb-uHObWPqnrw@mail.gmail.
9 Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-bash/2023-04/msg00082.html
13 When readline is accumulating bytes until it reads a complete multibyte
14 character, reading a byte that makes the multibyte character invalid can
15 result in discarding the bytes in the partial character.
17 Patch (apply with `patch -p0'):
19 *** ../readline-8.2-patched/text.c Mon May 1 09:37:52 2023
20 --- text.c Mon May 29 12:22:29 2023
23 rl_insert_text (const char *string)
27 l = (string && *string) ? strlen (string) : 0;
29 rl_insert_text (const char *string)
34 l = (string && *string) ? strlen (string) : 0;
37 /* Insert the character C at the current location, moving point forward.
38 If C introduces a multibyte sequence, we read the whole sequence and
39 ! then insert the multibyte char into the line buffer. */
41 _rl_insert_char (int count, int c)
43 /* Insert the character C at the current location, moving point forward.
44 If C introduces a multibyte sequence, we read the whole sequence and
45 ! then insert the multibyte char into the line buffer.
46 ! If C == 0, we immediately insert any pending partial multibyte character,
47 ! assuming that we have read a character that doesn't map to self-insert.
48 ! This doesn't completely handle characters that are part of a multibyte
49 ! character but map to editing functions. */
51 _rl_insert_char (int count, int c)
59 ! #if defined (HANDLE_MULTIBYTE)
60 ! if (MB_CUR_MAX == 1 || rl_byte_oriented)
66 + #if !defined (HANDLE_MULTIBYTE)
74 + if (pending_bytes_length == 0)
76 + if (stored_count <= 0)
77 + stored_count = count;
79 + count = stored_count;
81 ! memcpy (incoming, pending_bytes, pending_bytes_length);
82 ! incoming[pending_bytes_length] = '\0';
83 ! incoming_length = pending_bytes_length;
84 ! pending_bytes_length = 0;
85 ! memset (&ps, 0, sizeof (mbstate_t));
87 ! else if (MB_CUR_MAX == 1 || rl_byte_oriented)
93 else if (_rl_utf8locale && (c & 0x80) == 0)
95 + if (pending_bytes_length)
96 + _rl_insert_char (0, 0);
103 pending_bytes_length--;
104 ! memmove (pending_bytes, pending_bytes + 1, pending_bytes_length);
105 /* Clear the state of the byte sequence, because in this case the
106 effect of mbstate is undefined. */
109 pending_bytes_length--;
110 ! if (pending_bytes_length)
111 ! memmove (pending_bytes, pending_bytes + 1, pending_bytes_length);
112 /* Clear the state of the byte sequence, because in this case the
113 effect of mbstate is undefined. */
119 + #if defined (HANDLE_MULTIBYTE)
120 + return (pending_bytes_length != 0);
132 + return (pending_bytes_length != 0);
133 #else /* !HANDLE_MULTIBYTE */
134 char str[TEXT_COUNT_MAX+1];
139 - #endif /* !HANDLE_MULTIBYTE */
149 + #endif /* !HANDLE_MULTIBYTE */
165 ! return (pending_bytes_length != 0);
176 + /* If we didn't insert n and there are pending bytes, we need to insert
177 + them if _rl_insert_char didn't do that on its own. */
178 + if (r == 1 && rl_insert_mode == RL_IM_INSERT)
179 + r = _rl_insert_char (0, 0); /* flush partial multibyte char */
181 if (n != (unsigned short)-2) /* -2 = sentinel value for having inserted N */
186 rl_quoted_insert (int count, int key)
190 /* Let's see...should the callback interface futz with signal handling? */
191 #if defined (HANDLE_SIGNALS)
199 r = _rl_insert_next (1);
200 while (r == 0 && ++count < 0);
204 ! return _rl_insert_next (count);
211 r = _rl_insert_next (1);
212 while (r == 0 && ++count < 0);
215 + r = _rl_insert_next (count);
218 ! _rl_insert_char (0, 0); /* insert partial multibyte character */
224 *** ../readline-8.2/patchlevel 2013-11-15 08:11:11.000000000 -0500
225 --- patchlevel 2014-03-21 08:28:40.000000000 -0400
228 # Do not edit -- exists only for use by patch
232 # Do not edit -- exists only for use by patch