comparison src/message.c @ 28800:fea88e555652 v8.2.4924

patch 8.2.4924: maparg() may return a string that cannot be reused Commit: https://github.com/vim/vim/commit/0519ce00394474055bd58c089ea90a19986443eb Author: zeertzjq <zeertzjq@outlook.com> Date: Mon May 9 12:16:19 2022 +0100 patch 8.2.4924: maparg() may return a string that cannot be reused Problem: maparg() may return a string that cannot be reused. Solution: use msg_outtrans_special() instead of str2special(). (closes #10384)
author Bram Moolenaar <Bram@vim.org>
date Mon, 09 May 2022 13:30:03 +0200
parents d770568e6c98
children 9b292596a332
comparison
equal deleted inserted replaced
28799:6f38b93c8683 28800:fea88e555652
1719 text = "<Space>"; 1719 text = "<Space>";
1720 ++str; 1720 ++str;
1721 } 1721 }
1722 else 1722 else
1723 text = (char *)str2special(&str, from); 1723 text = (char *)str2special(&str, from);
1724 if (text[0] != NUL && text[1] == NUL)
1725 // single-byte character or illegal byte
1726 text = (char *)transchar_byte((char_u)text[0]);
1724 len = vim_strsize((char_u *)text); 1727 len = vim_strsize((char_u *)text);
1725 if (maxlen > 0 && retval + len >= maxlen) 1728 if (maxlen > 0 && retval + len >= maxlen)
1726 break; 1729 break;
1727 // Highlight special keys 1730 // Highlight special keys
1728 msg_puts_attr(text, len > 1 1731 msg_puts_attr(text, len > 1
1753 } 1756 }
1754 #endif 1757 #endif
1755 1758
1756 /* 1759 /*
1757 * Return the printable string for the key codes at "*sp". 1760 * Return the printable string for the key codes at "*sp".
1761 * On illegal byte return a string with only that byte.
1758 * Used for translating the lhs or rhs of a mapping to printable chars. 1762 * Used for translating the lhs or rhs of a mapping to printable chars.
1759 * Advances "sp" to the next code. 1763 * Advances "sp" to the next code.
1760 */ 1764 */
1761 char_u * 1765 char_u *
1762 str2special( 1766 str2special(
1796 } 1800 }
1797 if (IS_SPECIAL(c) || modifiers) // special key 1801 if (IS_SPECIAL(c) || modifiers) // special key
1798 special = TRUE; 1802 special = TRUE;
1799 } 1803 }
1800 1804
1801 if (has_mbyte && !IS_SPECIAL(c)) 1805 if (has_mbyte && !IS_SPECIAL(c) && MB_BYTE2LEN(c) > 1)
1802 { 1806 {
1803 char_u *p; 1807 char_u *p;
1804 1808
1805 *sp = str; 1809 *sp = str;
1806 // Try to un-escape a multi-byte character after modifiers. 1810 // Try to un-escape a multi-byte character after modifiers.
1807 p = mb_unescape(sp); 1811 p = mb_unescape(sp);
1808 1812 if (p != NULL)
1809 if (p == NULL) 1813 // Since 'special' is TRUE the multi-byte character 'c' will be
1810 { 1814 // processed by get_special_key_name()
1811 int len = (*mb_ptr2len)(str); 1815 c = (*mb_ptr2char)(p);
1812 1816 else
1813 // Check for an illegal byte. 1817 // illegal byte
1814 if (MB_BYTE2LEN(*str) > len) 1818 *sp = str + 1;
1815 {
1816 transchar_nonprint(curbuf, buf, c);
1817 *sp = str + 1;
1818 return buf;
1819 }
1820 *sp = str + len;
1821 p = str;
1822 }
1823 // Since 'special' is TRUE the multi-byte character 'c' will be
1824 // processed by get_special_key_name()
1825 c = (*mb_ptr2char)(p);
1826 } 1819 }
1827 else 1820 else
1821 // single-byte character or illegal byte
1828 *sp = str + 1; 1822 *sp = str + 1;
1829 1823
1830 // Make unprintable characters in <> form, also <M-Space> and <Tab>. 1824 // Make special keys and C0 control characters in <> form, also <M-Space>.
1831 // Use <Space> only for lhs of a mapping. 1825 // Use <Space> only for lhs of a mapping.
1832 if (special || char2cells(c) > 1 || (from && c == ' ')) 1826 if (special || c < ' ' || (from && c == ' '))
1833 return get_special_key_name(c, modifiers); 1827 return get_special_key_name(c, modifiers);
1834 buf[0] = c; 1828 buf[0] = c;
1835 buf[1] = NUL; 1829 buf[1] = NUL;
1836 return buf; 1830 return buf;
1837 } 1831 }