Re: Syntax file core dumps mc
- From: Roland Illig <roland illig gmx de>
- To: Roland Illig <roland illig gmx de>
- Cc: mc-devel gnome org, Ian Zagorskih <ianzag megasignal com>
- Subject: Re: Syntax file core dumps mc
- Date: Fri, 15 Apr 2005 23:39:44 +0200
Roland Illig wrote:
Ian Zagorskih wrote:
mc-4.6.1-pre4a
Synopsis:
Looks like mc core dumps when it cannot find "context default" section
in syntax file.
Thanks for the bug report. I can reproduce it, and I'm working on a
solution.
And here it is. The code that was erroneous was ugly, and so looks my
patch. It adds a field to the editor that notes how many rules have been
defined and takes its actions based on this number.
It has just been a weird idea to start an array with index 1 in C ...
I suggest that we replace code that uses NULL-terminated arrays with
code that has an extra length (or count, or whatever) field. That way we
can easily put assert()s before array indexes to ensure they are valid.
Roland
? mcedit-segv.patch
Index: edit-widget.h
===================================================================
RCS file: /cvsroot/mc/mc/edit/edit-widget.h,v
retrieving revision 1.24
diff -u -p -r1.24 edit-widget.h
--- edit-widget.h 3 Dec 2004 17:09:27 -0000 1.24
+++ edit-widget.h 15 Apr 2005 21:33:35 -0000
@@ -93,6 +93,7 @@ struct WEdit {
/* syntax higlighting */
struct _syntax_marker *syntax_marker;
struct context_rule **rules;
+ size_t rules_count; /* number of rules that are defined */
long last_get_rule;
struct syntax_rule rule;
char *syntax_type; /* description of syntax highlighting type being used */
Index: syntax.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/syntax.c,v
retrieving revision 1.73
diff -u -p -r1.73 syntax.c
--- syntax.c 22 Feb 2005 17:00:38 -0000 1.73
+++ syntax.c 15 Apr 2005 21:33:35 -0000
@@ -678,6 +678,7 @@ edit_read_syntax_rules (WEdit *edit, FIL
strcpy (whole_right, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_01234567890");
r = edit->rules = g_malloc (alloc_contexts * sizeof (struct context_rule *));
+ edit->rules_count = 0;
if (!edit->defines)
edit->defines = g_tree_new ((GCompareFunc) strcmp);
@@ -908,6 +909,7 @@ edit_read_syntax_rules (WEdit *edit, FIL
if (num_contexts == -1) {
return line;
}
+ edit->rules_count = num_contexts;
{
char *first_chars, *p;
@@ -932,17 +934,18 @@ edit_read_syntax_rules (WEdit *edit, FIL
void edit_free_syntax_rules (WEdit * edit)
{
- int i, j;
+ size_t i, j;
if (!edit)
return;
if (edit->defines)
destroy_defines (&edit->defines);
if (!edit->rules)
return;
- edit_get_rule (edit, -1);
+ if (edit->rules_count > 0)
+ edit_get_rule (edit, -1);
syntax_g_free (edit->syntax_type);
edit->syntax_type = 0;
- for (i = 0; edit->rules[i]; i++) {
+ for (i = 0; i < edit->rules_count; i++) {
if (edit->rules[i]->keyword) {
for (j = 0; edit->rules[i]->keyword[j]; j++) {
syntax_g_free (edit->rules[i]->keyword[j]->keyword);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]