Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Segfault in hrealloc somewhere between rpromts and syntax highlighting
On Apr 13, 2:29am, Jun T. wrote:
} Subject: Re: Segfault in hrealloc somewhere between rpromts and syntax hig
}
} 2014/04/06 16:05, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
} > index 3c7cff9..b916bd6 100644
} > (snip)
} > if (strcmp(zlemetaline, ol)) {
} > + zle_restore_positions();
}
} It seems this causes the following problem:
}
} $ echo foobar<RET>
} $ echo !$<TAB>
} $ echo fo
}
} Maybe zlemetacs/zlematall need not to be restored?
Hmm, I think it's more complicated than that. Assuming that the various
positions have been correctly updated when expansion changed the buffer,
then we don't want to restore *anything*, we just want to discard the
most recent saved state.
I'm not sure how that affects the state of any previous call to
zle_save_positions(), but I have to assume that if it's possible for
the stack to be more than one element deep here, then whoever else is
calling zle_store_positions() is planning to do a complete unwind of
whatever doexpandhist() may have done.
On the other hand, compresult.c simply makes sure that restoring the
positions doesn't affect zlemetall, so perhaps this is too much.
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index b916bd6..499c4ae 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -2795,7 +2795,7 @@ doexpandhist(void)
if (!err) {
zlemetacs = excs;
if (strcmp(zlemetaline, ol)) {
- zle_restore_positions();
+ zle_free_positions();
unmetafy_line();
/* For vi mode -- reset the beginning-of-insertion pointer *
* to the beginning of the line. This seems a little silly, *
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 9cfa881..1089e27 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -710,6 +710,27 @@ zle_restore_positions(void)
}
/*
+ * Discard positions previously saved, the line has been updated.
+ */
+
+/**/
+mod_export void
+zle_free_positions(void)
+{
+ struct zle_position *oldpos = zle_positions;
+ struct zle_region *oldrhp;
+
+ zle_positions = oldpos->next;
+ oldrhp = oldpos->regions;
+ while (oldrhp) {
+ struct zle_region *nextrhp = oldrhp->next;
+ zfree(oldrhp, sizeof(*oldrhp));
+ oldrhp = nextrhp;
+ }
+ zfree(oldpos, sizeof(*oldpos));
+}
+
+/*
* Basic utility functions for adding to line or removing from line.
* At this level the counts supplied are raw character counts, so
* the calling code must be aware of combining characters where
Messages sorted by:
Reverse Date,
Date,
Thread,
Author