Commit 86f158bc authored by Paul Eggert's avatar Paul Eggert

* doprnt.c (doprnt): Truncate multibyte char correctly.

Without this change, doprnt (buf, 2, "%s", FORMAT_END, AP)
would mishandle a string argument "Xc" if X was a multibyte
character of length 2: it would truncate after X's first byte
rather than including all of X.
parent b7014632
2012-06-07 Paul Eggert <eggert@cs.ucla.edu>
* doprnt.c (doprnt): Truncate multibyte char correctly.
Without this change, doprnt (buf, 2, "%s", FORMAT_END, AP)
would mishandle a string argument "Xc" if X was a multibyte
character of length 2: it would truncate after X's first byte
rather than including all of X.
2012-06-06 Chong Yidong <cyd@gnu.org>
* buffer.c (word_wrap): Doc fix.
......
......@@ -392,15 +392,19 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
{
/* Truncate the string at character boundary. */
tem = bufsize;
while (!CHAR_HEAD_P (string[tem - 1])) tem--;
/* If the multibyte sequence of this character is
too long for the space we have left in the
buffer, truncate before it. */
if (tem > 0
&& BYTES_BY_CHAR_HEAD (string[tem - 1]) > bufsize)
tem--;
if (tem > 0)
memcpy (bufptr, string, tem);
do
{
tem--;
if (CHAR_HEAD_P (string[tem]))
{
if (BYTES_BY_CHAR_HEAD (string[tem]) <= bufsize - tem)
tem = bufsize;
break;
}
}
while (tem != 0);
memcpy (bufptr, string, tem);
bufptr[tem] = 0;
/* Trigger exit from the loop, but make sure we
return to the caller a value which will indicate
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment