Stephen Riehm <[email protected]> wrote:
> Hi everyone,
>
> after upgrading from MacVim 104 to MacVim 106 I noticed that <M-"> no longer
> works (not recognised for maps - just inserts a ¢ character). (The problem
> also exists in 105 - which I missed).
>
> Workarounds such as <S-M-'> also had no effect.
>
> After a bit of git bisecting I found the following commit:
>
> 1d90a5a... patch 7.4.1968 Problem: Invalid memory access with "\<C-">.
> Solution: Do not recognize this as a special character. (Dominique Pelle)
>
> misc2.c line 2762 (as of commit 5009946)
>
> /* Anything accepted, like <C-?>, except <C-">, because the "
> * ends the string. */
> if (bp[l] != '"' && bp[l + 1] == '>')
> bp += l;
>
> This only checks for "> - thus not only catching <C-"> but also <M-">. (which
> always worked fine (for me at least :-)).
> Strangely, <D-"> was not adversely affected.
>
> After returning the check to its original
>
> if (bp[l + 1] == '>')
>
> <M-"> worked fine again.
>
> Also, even without the extra check, I still could not reproduce any problems
> via <C-"> (except that it only produced a ' character - Mac OS 10.9.5, MacVim
> Snapshot 106).
>
> Could we please revoke this patch, possibly replacing it with something else?
>
> IMHO: If the invalid memory access problem still exists, it should be solved
> by "not accessing invalid memory" rather than simply turning off / breaking
> useful functionality.
>
> Thanks in advance,
>
> Steve
Hi Steve
I attach a patch which re-allows <M-"> in mappings while
still fixing the memory error that was fixed in 7.4.1968.
Please confirm whether that works for you.
I verified that:
* all tests pass with the patch
* valgrind --num-callers=20 vim -u NONE -c 'echo "\<M-">' -c q 2> log
which reported memory errors before 7.4.1968 is still fixed.
* in gvim, mappings with <M-"> works (it was broken
by patch 7.4.1968). Example:
:imap <M-"> foo
Regards
Dominique
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/eval.c b/src/eval.c
index 45b8f07..d7f6180 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -4926,7 +4926,7 @@ get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
break;
/* Special key, e.g.: "\<C-W>" */
- case '<': extra = trans_special(&p, name, TRUE);
+ case '<': extra = trans_special(&p, name, TRUE, TRUE);
if (extra != 0)
{
name += extra;
@@ -4943,6 +4943,11 @@ get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
}
*name = NUL;
+ if (p == NUL)
+ {
+ EMSG2(_("E114: Missing quote: %s"), *arg);
+ return FAIL;
+ }
*arg = p + 1;
return OK;
diff --git a/src/gui_mac.c b/src/gui_mac.c
index b78c903..d750b3b 100644
--- a/src/gui_mac.c
+++ b/src/gui_mac.c
@@ -4830,7 +4830,7 @@ gui_mch_add_menu_item(vimmenu_T *menu, int idx)
char_u *p_actext;
p_actext = menu->actext;
- key = find_special_key(&p_actext, &modifiers, FALSE, FALSE);
+ key = find_special_key(&p_actext, &modifiers, FALSE, FALSE, FALSE);
if (*p_actext != 0)
key = 0; /* error: trailing text */
/* find_special_key() returns a keycode with as many of the
diff --git a/src/misc2.c b/src/misc2.c
index f44c33c..b8d60db 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -2674,13 +2674,14 @@ get_special_key_name(int c, int modifiers)
trans_special(
char_u **srcp,
char_u *dst,
- int keycode) /* prefer key code, e.g. K_DEL instead of DEL */
+ int keycode, /* prefer key code, e.g. K_DEL instead of DEL */
+ int in_string)
{
int modifiers = 0;
int key;
int dlen = 0;
- key = find_special_key(srcp, &modifiers, keycode, FALSE);
+ key = find_special_key(srcp, &modifiers, keycode, FALSE, in_string);
if (key == 0)
return 0;
@@ -2720,7 +2721,8 @@ find_special_key(
char_u **srcp,
int *modp,
int keycode, /* prefer key code, e.g. K_DEL instead of DEL */
- int keep_x_key) /* don't translate xHome to Home key */
+ int keep_x_key, /* don't translate xHome to Home key */
+ int in_string) /* when in string, don't translate \<C-">, \<M-"> */
{
char_u *last_dash;
char_u *end_of_name;
@@ -2751,9 +2753,10 @@ find_special_key(
else
#endif
l = 1;
- /* Anything accepted, like <C-?>, except <C-">, because the "
- * ends the string. */
- if (bp[l] != '"' && bp[l + 1] == '>')
+ /* Anything accepted, like <C-?>.
+ * <C-"> or <M-"> are not special in strings as " is
+ * the string delimiter. */
+ if (!(in_string && bp[l] == '"') && bp[l + 1] == '>')
bp += l;
}
}
diff --git a/src/option.c b/src/option.c
index d1a2533..f417e9c 100644
--- a/src/option.c
+++ b/src/option.c
@@ -9478,7 +9478,7 @@ find_key_option(char_u *arg)
{
--arg; /* put arg at the '<' */
modifiers = 0;
- key = find_special_key(&arg, &modifiers, TRUE, TRUE);
+ key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
if (modifiers) /* can't handle modifiers here */
key = 0;
}
diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro
index 573dee5..70c7dae 100644
--- a/src/proto/misc2.pro
+++ b/src/proto/misc2.pro
@@ -64,8 +64,8 @@ int name_to_mod_mask(int c);
int simplify_key(int key, int *modifiers);
int handle_x_keys(int key);
char_u *get_special_key_name(int c, int modifiers);
-int trans_special(char_u **srcp, char_u *dst, int keycode);
-int find_special_key(char_u **srcp, int *modp, int keycode, int keep_x_key);
+int trans_special(char_u **srcp, char_u *dst, int keycode, int in_string);
+int find_special_key(char_u **srcp, int *modp, int keycode, int keep_x_key, int in_string);
int extract_modifiers(int key, int *modp);
int find_special_key_in_table(int c);
int get_special_key_code(char_u *name);
diff --git a/src/syntax.c b/src/syntax.c
index 0face62..19f9bc4 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -7939,7 +7939,7 @@ do_highlight(
*/
for (p = arg, off = 0; off < 100 - 6 && *p; )
{
- len = trans_special(&p, buf + off, FALSE);
+ len = trans_special(&p, buf + off, FALSE, FALSE);
if (len > 0) /* recognized special char */
off += len;
else /* copy as normal char */
diff --git a/src/term.c b/src/term.c
index 344fabc..774ef65 100644
--- a/src/term.c
+++ b/src/term.c
@@ -5429,7 +5429,7 @@ replace_termcodes(
}
#endif
- slen = trans_special(&src, result + dlen, TRUE);
+ slen = trans_special(&src, result + dlen, TRUE, FALSE);
if (slen)
{
dlen += slen;