diff mbox series

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

Message ID 0ea78f2dddbb59ce2c984c83ab45cd811191b499.1675798292.git.nabijaczleweli@nabijaczleweli.xyz (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series [1/6] fc -s: refuse multiple events instead of ignoring | expand

Commit Message

Ahelenia ZiemiaƄska Feb. 7, 2023, 7:33 p.m. UTC
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@gigawatt.nl>
Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2
---
 src/histedit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

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;
 
 	/*