From: Omar Polo Subject: Re: ksh: use strtonum() To: "Todd C. Miller" Cc: tech@openbsd.org Date: Tue, 27 Aug 2024 20:50:54 +0200 On 2024/08/26 18:49:53 -0600, Todd C. Miller wrote: > On Mon, 26 Aug 2024 23:43:54 +0200, Omar Polo wrote: > > > I don't think, because it is expected to handle also !-N which is > > different from !N. > > > > It's the `start + rec + 1' part at the end of the function that handles > > the negative numbers turning them into the offset of the _last_ nth > > command, instead of the nth command. > > Ah, I see. So that: > return start + rec + 1; > > is equivalent to: > return rec + maxhist; yep. actually, i think it would be easier if written like this Index: history.c =================================================================== RCS file: /cvs/src/bin/ksh/history.c,v diff -u -p -r1.85 history.c --- history.c 27 Aug 2024 18:45:58 -0000 1.85 +++ history.c 27 Aug 2024 18:48:12 -0000 @@ -509,7 +509,6 @@ findhistrel(const char *str) { const char *errstr; int maxhist = histptr - history; - int start = maxhist - 1; int rec; rec = strtonum(str, -maxhist, maxhist, &errstr); @@ -520,7 +519,7 @@ findhistrel(const char *str) return -1; if (rec > 0) return rec - 1; - return start + rec + 1; + return maxhist + rec; } void