emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/emacs-24 r108508: * doprnt.c (doprnt): Trun


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-24 r108508: * doprnt.c (doprnt): Truncate multibyte char correctly.
Date: Fri, 02 Nov 2012 02:20:10 -0000
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108508
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Wed 2012-06-06 22:11:51 -0700
message:
  * 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.
modified:
  src/ChangeLog
  src/doprnt.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-06-06 06:39:24 +0000
+++ b/src/ChangeLog     2012-06-07 05:11:51 +0000
@@ -1,3 +1,11 @@
+2012-06-07  Paul Eggert  <address@hidden>
+
+       * 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  <address@hidden>
 
        * buffer.c (word_wrap): Doc fix.

=== modified file 'src/doprnt.c'
--- a/src/doprnt.c      2012-02-10 18:58:48 +0000
+++ b/src/doprnt.c      2012-06-07 05:11:51 +0000
@@ -392,15 +392,19 @@
                {
                  /* 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]