summaryrefslogtreecommitdiff
path: root/src/doprnt.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-04-30 12:00:39 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-04-30 12:00:39 -0700
commitb5611f17a7bd64578fc43874a727a8f1081614e9 (patch)
tree575f9ea23b1573410f853a1da842fb661753ff50 /src/doprnt.c
parentaec1708a5548072ba337a345fb72a184840eb0cb (diff)
parentdcb79f208ab9e2e1e8e0d4e9810ca25c1a660eaf (diff)
downloademacs-b5611f17a7bd64578fc43874a727a8f1081614e9.tar.gz
emacs-b5611f17a7bd64578fc43874a727a8f1081614e9.tar.bz2
emacs-b5611f17a7bd64578fc43874a727a8f1081614e9.zip
Merge from mainline.
Diffstat (limited to 'src/doprnt.c')
-rw-r--r--src/doprnt.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/doprnt.c b/src/doprnt.c
index e9a68f9d219..7b4bd35d5b1 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -269,7 +269,7 @@ doprnt (char *buffer, register size_t bufsize, const char *format,
long long ll = va_arg (ap, long long);
sprintf (sprintf_buffer, fmtcpy, ll);
#else
- abort ();
+ error ("Invalid format operation %%ll%c", fmt[-1]);
#endif
}
else if (long_flag)
@@ -299,7 +299,7 @@ doprnt (char *buffer, register size_t bufsize, const char *format,
unsigned long long ull = va_arg (ap, unsigned long long);
sprintf (sprintf_buffer, fmtcpy, ull);
#else
- abort ();
+ error ("Invalid format operation %%ll%c", fmt[-1]);
#endif
}
else if (long_flag)
@@ -367,9 +367,21 @@ doprnt (char *buffer, register size_t bufsize, const char *format,
/* Truncate the string at character boundary. */
tem = bufsize;
while (!CHAR_HEAD_P (string[tem - 1])) tem--;
- memcpy (bufptr, string, tem);
- /* We must calculate WIDTH again. */
- width = strwidth (bufptr, 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);
+ bufptr[tem] = 0;
+ /* Trigger exit from the loop, but make sure we
+ return to the caller a value which will indicate
+ that the buffer was too small. */
+ bufptr += bufsize;
+ bufsize = 0;
+ continue;
}
else
memcpy (bufptr, string, tem);