Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: minor zle_utils fix



Addressing these two points:

> Your way's probably neater; we probably don't need to lose too much
> sleep about the efficiency of the old interface as long as it's not too
> gross.  So the patch will need matching free()s in all callers.  I think
> there's just one at the moment.

> As discussed previously, this should just be zlell; we are not using
> terminating wide nulls.  This fits in with current usage where we don't
> use terminating ordinary nulls since an ASCII NUL is a valid character
> in unsigned char *zleline.

M  Src/Zle/zle_utils.c
M  Src/hist.c

* modified files

--- orig/Src/Zle/zle_utils.c
+++ mod/Src/Zle/zle_utils.c
@@ -89,10 +89,35 @@
 mod_export unsigned char *
 zlegetline(int *ll, int *cs)
 {
+    char *s;
+#ifdef ZLE_UNICODE_SUPPORT
+    char *mb_cursor;
+    int i, j;
+    size_t mb_len = 0;
+
+    mb_cursor = s = zalloc(zlell * MB_CUR_MAX);
+
+    for(i=0;i<=zlell;i++) {
+	if (i == zlecs)
+	    *cs = mb_len;
+	j = wctomb(mb_cursor, zleline[i]);
+	if (j == -1) {
+	    /* invalid char; what to do? */
+	} else {
+	    mb_len += j;
+	}
+    }
+
+    *ll = mb_len;
+
+    return (unsigned char *)s;
+#else
     *ll = zlell;
     *cs = zlecs;
 
-    return zleline;
+    s = ztrdup(zleline);
+    return (unsigned char *)s;
+#endif
 }
 
 


--- orig/Src/hist.c
+++ mod/Src/hist.c
@@ -2260,7 +2260,7 @@
 	if (zlegetlineptr) {
 	    linein = zlegetlineptr(&ll, &cs);
 	} else {
-	    linein = "";
+	    linein = ztrdup("");
 	    ll = cs = 0;
 	}
 	zlell = ll + 1; /* length of line plus space added below */
@@ -2287,6 +2287,7 @@
 	    p[zlell] = '\0';
 	    inpush(p, 0, NULL);
 	}
+    zsfree(linein);
     }
     if (zlecs)
 	zlecs--;




Messages sorted by: Reverse Date, Date, Thread, Author