mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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).
This commit is contained in:
parent
3a3816c990
commit
40feac6efc
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user