Dash Archive mirror
 help / color / mirror / Atom feed
From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: dash@vger.kernel.org
Subject: [PATCH] exec: hashcmd: don't early-exit when first -r is found
Date: Wed, 14 Dec 2022 03:51:13 +0100	[thread overview]
Message-ID: <20221214025113.c6lxog5v3wp4vzbt@tarta.nabijaczleweli.xyz> (raw)

[-- Attachment #1: Type: text/plain, Size: 1843 bytes --]

This fixes incorrectly-accepted "hash -rv" being equivalent to hash -r
(well, hash -r[literally anything] being equivalent to hash -r)

Also remove -v from the manual, it doesn't appear to have ever existed

Fixes: https://bugs.debian.org/819829
---
 src/dash.1 | 6 ++----
 src/exec.c | 8 +++++++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/dash.1 b/src/dash.1
index ff02237..3e09090 100644
--- a/src/dash.1
+++ b/src/dash.1
@@ -1441,7 +1441,8 @@ cmd \-a \-c arg file file
 cmd \-carg -a file file
 cmd \-a \-carg \-\- file file
 .Ed
-.It hash Fl rv Ar command ...
+.It hash Op Ar command ...
+.It hash Fl r
 The shell maintains a hash table which remembers the
 locations of commands.
 With no arguments whatsoever,
@@ -1457,9 +1458,6 @@ With arguments, the
 .Ic hash
 command removes the specified commands from the hash table (unless
 they are functions) and then locates them.
-With the
-.Fl v
-option, hash prints the locations of the commands as it finds them.
 The
 .Fl r
 option causes the hash command to delete all the entries in the hash table
diff --git a/src/exec.c b/src/exec.c
index 87354d4..d7a1f53 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #ifdef HAVE_PATHS_H
 #include <paths.h>
@@ -271,11 +272,16 @@ hashcmd(int argc, char **argv)
 	int c;
 	struct cmdentry entry;
 	char *name;
+	bool clear;
 
-	while ((c = nextopt("r")) != '\0') {
+	clear = false;
+	while ((c = nextopt("r")) != '\0')
+		clear = true;
+	if(clear) {
 		clearcmdentry();
 		return 0;
 	}
+
 	if (*argptr == NULL) {
 		for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
 			for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-- 
2.30.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2022-12-14  2:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14  2:51 наб [this message]
2023-01-05  9:44 ` [PATCH] exec: hashcmd: don't early-exit when first -r is found Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221214025113.c6lxog5v3wp4vzbt@tarta.nabijaczleweli.xyz \
    --to=nabijaczleweli@nabijaczleweli.xyz \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).