[prev in list] [next in list] [prev in thread] [next in thread] 

List:       dash
Subject:    [PATCH 5/6] fc: fix "fc -3" extension on glibc
From:       наб <nabijaczleweli () nabijaczleweli ! xyz>
Date:       2023-02-07 19:33:42
Message-ID: 0ea78f2dddbb59ce2c984c83ab45cd811191b499.1675798292.git.nabijaczleweli () nabijaczleweli ! xyz
[Download RAW message or body]


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 --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


["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic