Hi, On Thu, 2006-02-02 at 20:33 +0100, Leonard den Ottolander wrote: > Ran mc from a temporary build dir and copied Syntax to ~/.mc/cedit/ . > Tried editing a file and saw a segfault when the non existent syntax > file is attempted to be loaded. > > #0 edit_get_rule (edit=0x92e8dc0, byte_index=-1) at syntax.c:285 > #1 0x080a4161 in edit_free_syntax_rules (edit=0x92e8dc0) at > syntax.c:977
A fix is attached. When edit_load_syntax() fails on Syntax because the target syntax file is missing there are no syntax rules to be freed, just an uninitialized rules block. That block needs to be (freed and) set to NULL or the editor will attempt to load the block as if it were valid rules and still crash. Leonard. -- mount -t life -o ro /dev/dna /genetic/research
--- mc.000/edit/syntax.c 2006-02-08 14:54:44.000000000 +0100 +++ mc/edit/syntax.c 2006-03-26 23:32:00.000000000 +0200 @@ -660,6 +660,7 @@ this_try_alloc_color_pair (const char *f } static char *error_file_name = 0; +static int error_file_is_Syntax = 0; static FILE *open_include_file (const char *filename) { @@ -1110,6 +1111,8 @@ edit_read_syntax_file (WEdit * edit, cha int line_error; char *syntax_type; found_type: + if (g) + error_file_is_Syntax = 0; syntax_type = args[2]; line_error = edit_read_syntax_rules (edit, g ? g : f, args, 1023); if (line_error) { @@ -1189,6 +1192,7 @@ edit_load_syntax (WEdit *edit, char ***p if (!*edit->filename && !type) return; } + error_file_is_Syntax = 1; f = concat_dir_and_file (home_dir, SYNTAX_FILE); r = edit_read_syntax_file (edit, pnames, f, edit ? edit->filename : 0, get_first_editor_line (edit), type); @@ -1198,7 +1202,12 @@ edit_load_syntax (WEdit *edit, char ***p _(" Cannot open file %s \n %s "), f, unix_error_string (errno)); } else if (r) { - edit_free_syntax_rules (edit); + if (error_file_is_Syntax != 1) + edit_free_syntax_rules (edit); + else { + g_free(edit->rules); + edit->rules = NULL; + } message (D_ERROR, _(" Load syntax file "), _(" Error in file %s on line %d "), error_file_name ? error_file_name : f, r);
_______________________________________________ Mc-devel mailing list http://mail.gnome.org/mailman/listinfo/mc-devel