diff options
author | ZyX <kp-pav@yandex.ru> | 2016-09-10 22:32:14 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-29 10:08:06 +0300 |
commit | 40feac6efcc75395bb20da2b028b67a2b6e95bd9 (patch) | |
tree | 2bb2b9d8845c287cf3895b755432ca9d902639c7 /src | |
parent | 3a3816c990362e1ad8321e6b4748a33c94d1d797 (diff) | |
download | rneovim-40feac6efcc75395bb20da2b028b67a2b6e95bd9.tar.gz rneovim-40feac6efcc75395bb20da2b028b67a2b6e95bd9.tar.bz2 rneovim-40feac6efcc75395bb20da2b028b67a2b6e95bd9.zip |
message: Revise maxlen argument in msg_puts_attr_len
`attr` argument is enough to forbid putting message in history. Also forbid
strings with NUL before `len` just in case (it appears that this does not ever
happen).
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/message.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c index 423f5a27e7..1eab9a403b 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1562,13 +1562,17 @@ void msg_puts_attr(const char *const s, const int attr) msg_puts_attr_len(s, -1, attr); } -/// Like msg_puts_attr(), but with a maximum length "maxlen" (in bytes). -/// When "maxlen" is -1 there is no maximum length. -/// When "maxlen" is >= 0 the message is not put in the history. -void msg_puts_attr_len(const char *str, const ptrdiff_t maxlen, int attr) +/// Write a message with highlight attributes +/// +/// @param[in] str NUL-terminated message string. +/// @param[in] len Length of the string or -1. +/// @param[in] attr Highlight attribute. +void msg_puts_attr_len(const char *const str, const ptrdiff_t len, int attr) + FUNC_ATTR_NONNULL_ALL { + assert(len < 0 || memchr(str, 0, len) == NULL); // If redirection is on, also write to the redirection file. - redir_write(str, maxlen); + redir_write(str, len); // Don't print anything when using ":silent cmd". if (msg_silent != 0) { @@ -1576,8 +1580,9 @@ void msg_puts_attr_len(const char *str, const ptrdiff_t maxlen, int attr) } // if MSG_HIST flag set, add message to history - if ((attr & MSG_HIST) && maxlen < 0) { - add_msg_hist(str, -1, attr); + if (attr & MSG_HIST) { + assert(len < 0); + add_msg_hist(str, (int)len, attr); attr &= ~MSG_HIST; } @@ -1596,9 +1601,9 @@ void msg_puts_attr_len(const char *str, const ptrdiff_t maxlen, int attr) // different, e.g. for Win32 console) or we just don't know where the // cursor is. if (msg_use_printf()) { - msg_puts_printf(str, maxlen); + msg_puts_printf(str, len); } else { - msg_puts_display((const char_u *)str, maxlen, attr, false); + msg_puts_display((const char_u *)str, len, attr, false); } } |