2011-04-09 Paul Eggert <eggert@cs.ucla.edu>
+ * xdisp.c (vmessage): Use a better test for character truncation.
+
* charset.c (load_charset_map): <, not <=, for optimization,
and to avoid potential problems with integer overflow.
* chartab.c (sub_char_table_set_range, char_table_set_range): Likewise.
{
char *buf = FRAME_MESSAGE_BUF (f);
size_t bufsize = FRAME_MESSAGE_BUF_SIZE (f);
- int len = vsnprintf (buf, bufsize, m, ap);
- if (len < 0)
- len = 0;
+ int len;
+
+ memset (buf, 0, bufsize);
+ len = vsnprintf (buf, bufsize, m, ap);
/* Do any truncation at a character boundary. */
- if (0 < bufsize && bufsize <= len)
- for (len = bufsize - 1;
+ if (! (0 <= len && len < bufsize))
+ for (len = strnlen (buf, bufsize);
len && ! CHAR_HEAD_P (buf[len - 1]);
len--)
continue;
EMACS_INT limit = BUF_BEGV (b);
EMACS_INT limit_byte = BUF_BEGV_BYTE (b);
EMACS_INT position;
- EMACS_INT distance =
+ EMACS_INT distance =
(height * 2 + 30) * line_number_display_limit_width;
if (startpos - distance > limit)