Syntax file crash mc: probable fixed
- From: "Andrew V. Samoilov" <kai cmail ru>
- To: Pavel Roskin <proski gnu org>
- Cc: GNU Midnight Commander Development Team <mc-devel gnome org>
- Subject: Syntax file crash mc: probable fixed
- Date: Wed, 28 Nov 2001 17:44:47 +0200
Hi, Pavel!
This patch fixes crushes in built-in editor
with incorrect Syntax file(s). Unfortunately I have not
time to test it hardly. In worse scenario I will be
offline for a 3 weeks, so commit it please if you find it right.
I am too harry now to make sure I break nothing.
Regards,
Andrew.
ChangeLog:
* syntax.c (syntax_g_free): New macros. Use to release
and NULLify glib allocated memory area(s).
(strdup_convert): Rename to ...
(convert): ... this. Don't strdup passed string.
(get_args): Use convert instead of strdup_convert.
(free_args): Make it do notning macros.
(open_include_file): Eliminate p array. Use glib
functions to construct error_file_name. Use PATH_SEP_STR
instead of "/".
(edit_read_syntax_rules): Use syntax_g_free to release
error_file_name.
(edit_load_syntax): Likewise.
--- mc-cvs/edit/syntax.c Wed Nov 28 17:15:06 2001
+++ mc/edit/syntax.c Wed Nov 28 17:17:37 2001
@@ -68,6 +68,7 @@ static void *syntax_malloc (size_t x)
}
#define syntax_free(x) {if(x){free(x);(x)=0;}}
+#define syntax_g_free(x) {if(x){g_free(x);(x)=0;}}
static long compare_word_to_right (WEdit * edit, long i, char *text, char *whole_left, char *whole_right, int line_start)
{
@@ -428,10 +429,10 @@ static int read_one_line (char **line, F
return r;
}
-static char *strdup_convert (char *s)
+static char *convert (char *s)
{
char *r, *p;
- p = r = (char *) strdup (s);
+ p = r = s;
while (*s) {
switch (*s) {
case '\\':
@@ -503,13 +505,13 @@ static void get_args (char *l, char **ar
for (l = p + 1; *l && !whiteness (*l); l++);
if (*l)
*l++ = '\0';
- *args = strdup_convert (p);
+ *args = convert (p);
(*argc)++;
args++;
}
*args = 0;
}
-
+#if 0
static void free_args (char **args)
{
while (*args) {
@@ -517,6 +519,9 @@ static void free_args (char **args)
args++;
}
}
+#else
+#define free_args(x)
+#endif
#define break_a {result=line;break;}
#define check_a {if(!*a){result=line;break;}}
@@ -557,25 +562,23 @@ extern char *mc_home;
static FILE *open_include_file (char *filename)
{
FILE *f;
- char p[MAX_PATH_LEN];
- syntax_free (error_file_name);
- error_file_name = (char *) strdup (filename);
+
+ syntax_g_free (error_file_name);
+ error_file_name = g_strdup (filename);
if (*filename == '/')
return fopen (filename, "r");
- strcpy (p, home_dir);
- strcat (p, EDIT_DIR "/");
- strcat (p, filename);
- syntax_free (error_file_name);
- error_file_name = (char *) strdup (p);
- f = fopen (p, "r");
+
+ syntax_g_free (error_file_name);
+ error_file_name = g_strconcat (home_dir, EDIT_DIR PATH_SEP_STR,
+ filename, NULL);
+ f = fopen (error_file_name, "r");
if (f)
return f;
- strcpy (p, mc_home);
- strcat (p, "/syntax/");
- strcat (p, filename);
- syntax_free (error_file_name);
- error_file_name = (char *) strdup (p);
- return fopen (p, "r");
+
+ syntax_g_free (error_file_name);
+ error_file_name = g_strconcat (mc_home, PATH_SEP_STR "syntax" PATH_SEP_STR,
+ filename, NULL);
+ return fopen (error_file_name, "r");
}
/* returns line number on error */
@@ -610,7 +613,7 @@ static int edit_read_syntax_rules (WEdit
f = g;
g = 0;
line = save_line + 1;
- syntax_free (error_file_name);
+ syntax_g_free (error_file_name);
if (l)
syntax_free (l);
if (!read_one_line (&l, f))
@@ -631,7 +634,7 @@ static int edit_read_syntax_rules (WEdit
g = f;
f = open_include_file (args[1]);
if (!f) {
- syntax_free (error_file_name);
+ syntax_g_free (error_file_name);
result = line;
break;
}
@@ -1001,7 +1004,7 @@ void edit_load_syntax (WEdit * edit, cha
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);
+ syntax_g_free (error_file_name);
return;
}
}
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]