diff options
| author | Paul Eggert | 2012-06-06 22:11:51 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-06-06 22:11:51 -0700 |
| commit | 86f158bc15cd63740131ca102179c760a691e4c8 (patch) | |
| tree | 98c2e9ae3581147606cd4604f8cc122cf6faba4e /src | |
| parent | b7014632a628bfb2a44fdb426e7ab145cc6a2eb5 (diff) | |
| download | emacs-86f158bc15cd63740131ca102179c760a691e4c8.tar.gz emacs-86f158bc15cd63740131ca102179c760a691e4c8.zip | |
* 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/doprnt.c | 22 |
2 files changed, 21 insertions, 9 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 7ea9ad8f3e3..3acf12e4483 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2012-06-07 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | * doprnt.c (doprnt): Truncate multibyte char correctly. | ||
| 4 | Without this change, doprnt (buf, 2, "%s", FORMAT_END, AP) | ||
| 5 | would mishandle a string argument "Xc" if X was a multibyte | ||
| 6 | character of length 2: it would truncate after X's first byte | ||
| 7 | rather than including all of X. | ||
| 8 | |||
| 1 | 2012-06-06 Chong Yidong <cyd@gnu.org> | 9 | 2012-06-06 Chong Yidong <cyd@gnu.org> |
| 2 | 10 | ||
| 3 | * buffer.c (word_wrap): Doc fix. | 11 | * buffer.c (word_wrap): Doc fix. |
diff --git a/src/doprnt.c b/src/doprnt.c index df9ebc11f9c..b106ffb1938 100644 --- a/src/doprnt.c +++ b/src/doprnt.c | |||
| @@ -392,15 +392,19 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format, | |||
| 392 | { | 392 | { |
| 393 | /* Truncate the string at character boundary. */ | 393 | /* Truncate the string at character boundary. */ |
| 394 | tem = bufsize; | 394 | tem = bufsize; |
| 395 | while (!CHAR_HEAD_P (string[tem - 1])) tem--; | 395 | do |
| 396 | /* If the multibyte sequence of this character is | 396 | { |
| 397 | too long for the space we have left in the | 397 | tem--; |
| 398 | buffer, truncate before it. */ | 398 | if (CHAR_HEAD_P (string[tem])) |
| 399 | if (tem > 0 | 399 | { |
| 400 | && BYTES_BY_CHAR_HEAD (string[tem - 1]) > bufsize) | 400 | if (BYTES_BY_CHAR_HEAD (string[tem]) <= bufsize - tem) |
| 401 | tem--; | 401 | tem = bufsize; |
| 402 | if (tem > 0) | 402 | break; |
| 403 | memcpy (bufptr, string, tem); | 403 | } |
| 404 | } | ||
| 405 | while (tem != 0); | ||
| 406 | |||
| 407 | memcpy (bufptr, string, tem); | ||
| 404 | bufptr[tem] = 0; | 408 | bufptr[tem] = 0; |
| 405 | /* Trigger exit from the loop, but make sure we | 409 | /* Trigger exit from the loop, but make sure we |
| 406 | return to the caller a value which will indicate | 410 | return to the caller a value which will indicate |