From: Omar Polo Subject: ksh: use strtonum() To: tech@openbsd.org Date: Mon, 26 Aug 2024 10:47:42 +0200 I decided to give it a try :) atoi() is only used in findhistrel(), which in turn is only used if you enable csh-like history. findhistrel() is used only once in lex.c. it is expected to return the item in the history array to lookup. Regress still passes (not suprising since csh-history is not tested) and runtime testing seems to behave just like before. I do enable and use csh-style history expansion, but admittedly only in the most basic forms. diff /usr/src commit - cfb8aef91a90e62370ec0c79ff80c4089a8f0cfb path + /usr/src blob - c768563496eccde8ced1df4a6bd73ee967a1cfff file + bin/ksh/history.c --- bin/ksh/history.c +++ bin/ksh/history.c @@ -507,19 +507,19 @@ findhist(int start, int fwd, const char *str, int anch int findhistrel(const char *str) { + const char *errstr; int maxhist = histptr - history; int start = maxhist - 1; - int rec = atoi(str); + int rec; + rec = strtonum(str, -maxhist, maxhist, &errstr); + if (errstr) + return -1; + if (rec == 0) return -1; - if (rec > 0) { - if (rec > maxhist) - return -1; + if (rec > 0) return rec - 1; - } - if (rec > maxhist) - return -1; return start + rec + 1; }