[PATCH 5/6] fc: fix "fc -3" extension on glibc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Before:
	$ echo a
	a
	$ echo b
	b
	$ fc -2 -1
	src/dash: 3: fc: unknown option: -2
	$ fc -- -2 -1
	16
	,p
	echo b
	fc -2 -1
After:
	$ echo a
	a
	$ echo b
	b
	$ fc -2 -1
	6
	,p
	echo a
	echo b

Reported-by: Harald van Dijk <harald@xxxxxxxxxxx>
Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2
---
 src/histedit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/histedit.c b/src/histedit.c
index f10e5ab..502ad40 100644
--- a/src/histedit.c
+++ b/src/histedit.c
@@ -217,7 +217,7 @@ histcmd(int argc, char **argv)
 #else
 	optreset = 1; optind = 1; /* initialize getopt */
 #endif
-	while (not_fcnumber(argv[optind]) &&
+	while (not_fcnumber(argv[optind ?: 1]) &&
 	      (ch = getopt(argc, argv, ":e:lnrs")) != -1)
 		switch ((char)ch) {
 		case 'e':
@@ -243,6 +243,7 @@ histcmd(int argc, char **argv)
 			sh_error("unknown option: -%c", optopt);
 			/* NOTREACHED */
 		}
+	optind = optind ?: 1;
 	argc -= optind, argv += optind;
 
 	/*
-- 
2.30.2

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux