summaryrefslogtreecommitdiff
path: root/Src/Zle/zle_utils.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2014-12-16 21:14:16 +0000
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2014-12-18 18:54:55 +0000
commit04e555a92e49eb41f4321c67511bec94a86b867a (patch)
treebbd87dee69e6878c3e18c5bf1aa987611cc62177 /Src/Zle/zle_utils.c
parentfe51f39dadfc2a1651ac92edfb783f1e6100b7b1 (diff)
downloadzsh-04e555a92e49eb41f4321c67511bec94a86b867a.tar.gz
zsh-04e555a92e49eb41f4321c67511bec94a86b867a.zip
33981: more care with region_highlights management
Diffstat (limited to 'Src/Zle/zle_utils.c')
-rw-r--r--Src/Zle/zle_utils.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index de91182b5..e361e5e2a 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -675,35 +675,42 @@ zle_restore_positions(void)
zlell = oldpos->ll;
}
- /* Count number of regions and see if the array needs resizing */
- for (nreg = 0, oldrhp = oldpos->regions;
- oldrhp;
- nreg++, oldrhp = oldrhp->next)
- ;
- if (nreg + N_SPECIAL_HIGHLIGHTS != n_region_highlights) {
- n_region_highlights = nreg + N_SPECIAL_HIGHLIGHTS;
- region_highlights = (struct region_highlight *)
- zrealloc(region_highlights,
- sizeof(struct region_highlight) * n_region_highlights);
- }
- oldrhp = oldpos->regions;
- rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
- while (oldrhp) {
- struct zle_region *nextrhp = oldrhp->next;
-
- rhp->atr = oldrhp->atr;
- rhp->flags = oldrhp->flags;
- if (zlemetaline) {
- rhp->start_meta = oldrhp->start;
- rhp->end_meta = oldrhp->end;
- } else {
- rhp->start = oldrhp->start;
- rhp->end = oldrhp->end;
+ if (oldpos->regions) {
+ /* Count number of regions and see if the array needs resizing */
+ for (nreg = 0, oldrhp = oldpos->regions;
+ oldrhp;
+ nreg++, oldrhp = oldrhp->next)
+ ;
+ if (nreg + N_SPECIAL_HIGHLIGHTS != n_region_highlights) {
+ n_region_highlights = nreg + N_SPECIAL_HIGHLIGHTS;
+ region_highlights = (struct region_highlight *)
+ zrealloc(region_highlights,
+ sizeof(struct region_highlight) * n_region_highlights);
}
+ oldrhp = oldpos->regions;
+ rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
+ while (oldrhp) {
+ struct zle_region *nextrhp = oldrhp->next;
- zfree(oldrhp, sizeof(*oldrhp));
- oldrhp = nextrhp;
- rhp++;
+ rhp->atr = oldrhp->atr;
+ rhp->flags = oldrhp->flags;
+ if (zlemetaline) {
+ rhp->start_meta = oldrhp->start;
+ rhp->end_meta = oldrhp->end;
+ } else {
+ rhp->start = oldrhp->start;
+ rhp->end = oldrhp->end;
+ }
+
+ zfree(oldrhp, sizeof(*oldrhp));
+ oldrhp = nextrhp;
+ rhp++;
+ }
+ } else if (region_highlights) {
+ zfree(region_highlights, sizeof(struct region_highlight) *
+ n_region_highlights);
+ region_highlights = NULL;
+ n_region_highlights = 0;
}
zfree(oldpos, sizeof(*oldpos));