Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: $history index in prompt_bart_precmd
- X-seq: zsh-workers 10614
 
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
 
- To: zsh-workers@xxxxxxxxxxxxxx
 
- Subject: Re: PATCH: $history index in prompt_bart_precmd
 
- Date: Mon, 10 Apr 2000 10:20:26 +0200 (MET DST)
 
- In-reply-to: "Bart Schaefer"'s message of Sat, 8 Apr 2000 20:55:14 +0000
 
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
 
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