+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.
{
/* 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