Syntax file crush mc
Andrew V. Samoilov
kai at cmail.ru
Wed Nov 28 12:57:26 UTC 2001
Hi!
Some minutes ago I committed patch below.
This one fixes crush in built-in editor with syntax highlighting
if Syntax file contain lines like
\s+ \n lightgray/13 red
But this 4 line Syntax file and many others still crush mc.
# syntax rules version 62
file .\*ChangeLog$ GNU\sDistribution\sChangeLog\sFile
# context [\ \t]+ \n lightgray/13
# end of Syntax.
(Hopeless attempt to highlight trailing whitespace(s)).
It seems something corrupts stack in syntax.c.
Unfortunately I have no time to hint this bug.
I am going to Moscow for 2-3 weeks and will have limited access
to Internet.
Regards,
Andrew.
Index: mc/edit/ChangeLog
diff -u mc/edit/ChangeLog:1.29 mc/edit/ChangeLog:1.30
--- mc/edit/ChangeLog:1.29 Tue Nov 27 07:38:30 2001
+++ mc/edit/ChangeLog Wed Nov 28 07:40:18 2001
@@ -1,3 +1,19 @@
+2001-11-28 Andrew V. Samoilov <kai at cmail.ru>
+
+ * syntax.c (apply_rules_going_right): Fix crush for lines like
+ \s+ \n lightgray/13 red
+ in Syntax file.
+ (read_one_line): Use EOF instead of -1.
+ (get_args): Fix buffer overflow for l without trailing
+ whitespace(s).
+ (break_a): New macro.
+ (edit_read_syntax_rules): Use break_a to fix memory leaks.
+ (edit_load_syntax): Eliminate s and use message to prevent
+ buffer overflow.
+
+ * editdraw.c (edit_render): Eliminate f. It's only written
+ but never read.
+
2001-11-27 Andrew V. Samoilov <kai at cmail.ru>
* editmenu.c (edit_wrap_cmd): Use g_free() on the result
Index: mc/edit/syntax.c
diff -u mc/edit/syntax.c:1.17 mc/edit/syntax.c:1.18
--- mc/edit/syntax.c:1.17 Tue Sep 11 17:44:52 2001
+++ mc/edit/syntax.c Wed Nov 28 07:40:18 2001
@@ -238,6 +238,7 @@
if (!_rule.keyword) {
char *p;
p = (r = edit->rules[_rule.context])->keyword_first_chars;
+ if (p)
while (*(p = xx_strchr ((unsigned char *) p + 1, c))) {
struct key_word *k;
int count;
@@ -402,7 +403,7 @@
#endif
for (;;) {
c = fgetc (f);
- if (c == -1) {
+ if (c == EOF) {
if (errno == EINTR)
continue;
r = 0;
@@ -493,14 +494,15 @@
static void get_args (char *l, char **args, int *argc)
{
*argc = 0;
- l--;
for (;;) {
- char *p;
- for (p = l + 1; *p && whiteness (*p); p++);
+ char *p = l;
+ while (*p && whiteness (*p))
+ p++;
if (!*p)
break;
for (l = p + 1; *l && !whiteness (*l); l++);
- *l = '\0';
+ if (*l)
+ *l++ = '\0';
*args = strdup_convert (p);
(*argc)++;
args++;
@@ -512,11 +514,11 @@
{
while (*args) {
syntax_free (*args);
- *args = 0;
args++;
}
}
+#define break_a {result=line;break;}
#define check_a {if(!*a){result=line;break;}}
#define check_not_a {if(*a){result=line;break;}}
@@ -653,8 +655,7 @@
check_a;
if (num_contexts == -1) {
if (strcmp (*a, "default")) { /* first context is the default */
- *a = 0;
- check_a;
+ break_a;
}
a++;
c = r[0] = syntax_malloc (sizeof (struct context_rule));
@@ -724,7 +725,7 @@
} else if (!strcmp (args[0], "keyword")) {
struct key_word *k;
if (num_words == -1)
- *a = 0;
+ break_a;
check_a;
k = r[num_contexts - 1]->keyword[num_words] = syntax_malloc (sizeof (struct key_word));
if (!strcmp (*a, "whole")) {
@@ -745,8 +746,7 @@
}
check_a;
if (!strcmp (*a, "whole")) {
- *a = 0;
- check_a;
+ break_a;
}
k->keyword = (char *) strdup (*a++);
k->first = *k->keyword;
@@ -768,8 +768,7 @@
} else if (!strcmp (args[0], "file")) {
break;
} else { /* anything else is an error */
- *a = 0;
- check_a;
+ break_a;
}
free_args (args);
syntax_free (l);
@@ -998,10 +997,10 @@
return;
}
if (r) {
- char s[80];
edit_free_syntax_rules (edit);
- sprintf (s, _ (" Error in file %s on line %d "), error_file_name ? error_file_name : f, r);
- edit_error_dialog (_ (" Load syntax file "), s);
+ message (0, _(" Load syntax file "),
+ _(" Error in file %s on line %d "),
+ error_file_name ? error_file_name : f, r);
syntax_free (error_file_name);
return;
}
More information about the mc-devel
mailing list