about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/zle_refresh.c7
-rw-r--r--Src/Zle/zle_utils.c61
2 files changed, 39 insertions, 29 deletions
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 467629d25..9f8075386 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -396,8 +396,9 @@ get_region_highlight(UNUSED(Param pm))
     struct region_highlight *rhp;
 
     /* region_highlights may not have been set yet */
-    if (arrsize)
-	arrsize -= N_SPECIAL_HIGHLIGHTS;
+    if (!arrsize)
+	return hmkarray(NULL);
+    arrsize -= N_SPECIAL_HIGHLIGHTS;
     arrp = retarr = (char **)zhalloc((arrsize+1)*sizeof(char *));
 
     /* ignore special highlighting */
@@ -1028,6 +1029,8 @@ zrefresh(void)
     /* this will create region_highlights if it's still NULL */
     zle_set_highlight();
 
+    DPUTS(!region_highlights, "region_highlights not created");
+
     /* check for region between point ($CURSOR) and mark ($MARK) */
     if (region_active) {
 	if (zlecs <= mark) {
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));