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

Re: PATCH: $history index in prompt_bart_precmd



Bart Schaefer wrote:

> ...
> 
> There is, however, some kind of bug with interpretation of the keys for
> $history, because e.g. $history[3-1] == $history[3].  (It should yield
> the empty string, as there isn't any hash table value for key "3-1".)

It was using atoi(). Yes, since this is supposed to be an assoc, we
should probably be more careful to check the index used.

Bye
 Sven

Index: Src/Modules/parameter.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v
retrieving revision 1.2
diff -u -r1.2 parameter.c
--- Src/Modules/parameter.c	2000/04/01 20:49:48	1.2
+++ Src/Modules/parameter.c	2000/04/10 08:20:17
@@ -1020,6 +1020,8 @@
 {
     Param pm = NULL;
     Histent he;
+    char *p;
+    int ok = 1;
 
     pm = (Param) zhalloc(sizeof(struct param));
     pm->nam = dupstring(name);
@@ -1032,7 +1034,17 @@
     pm->ename = NULL;
     pm->old = NULL;
     pm->level = 0;
-    if ((he = quietgethist(atoi(name))))
+
+    if (*name != '0' || name[1]) {
+	if (*name == '0')
+	    ok = 0;
+	else {
+	    for (p = name; *p && idigit(*p); p++);
+	    if (*p)
+		ok = 0;
+	}
+    }
+    if (ok && (he = quietgethist(atoi(name))))
 	pm->u.str = dupstring(he->text);
     else {
 	pm->u.str = dupstring("");

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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