public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [PATCH] Don't allow implicit file argument in combination with -o
Date: Mon, 22 Mar 2021 06:43:24 +0100	[thread overview]
Message-ID: <20210322054323.GA2676@delia> (raw)

Hi,

Consider this dwz usage:
...
$ gcc ~/hello.c -g
$ dwz -o b.out
$
...

According to the advertised usage:
...
$ dwz -?
Usage:
  dwz [common options] [-h] [-m COMMONFILE] [-M NAME | -r] [FILES]
  dwz [common options] -o OUTFILE FILE
  dwz [ -v | -? ]
...
the FILE argument is required when using -o OUTFILE.

Fix this by erroring out instead:
...
$ dwz -o b.out
dwz: Cannot use implicit file in combination with -o option
...

[ Alternatively, we could update the advertised usage. ]

Any comments?

Thanks,
- Tom

Don't allow implicit file argument in combination with -o

2021-03-22  Tom de Vries  <tdevries@suse.de>

	PR dwz/27595
	* dwz.c (main): Don't allow implicit file argument in combination
	with -o.
	* testsuite/dwz.tests/pr27595.sh: New test.

---
 dwz.c                          |  3 +++
 testsuite/dwz.tests/pr27595.sh | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/dwz.c b/dwz.c
index a7aa23b..fe191ba 100644
--- a/dwz.c
+++ b/dwz.c
@@ -16428,6 +16428,9 @@ main (int argc, char *argv[])
     {
       const char *file = nr_files == 0 ? "a.out" : files[0];
 
+      if (nr_files == 0 && outfile != NULL)
+	error (1, 0, "Cannot use implicit file in combination with -o option");
+
       if (multifile != NULL)
 	{
 	  error (0, 0, "Too few files for multifile optimization");
diff --git a/testsuite/dwz.tests/pr27595.sh b/testsuite/dwz.tests/pr27595.sh
new file mode 100644
index 0000000..bd459be
--- /dev/null
+++ b/testsuite/dwz.tests/pr27595.sh
@@ -0,0 +1,11 @@
+cp $execs/hello a.out
+
+if dwz -o b.out 2> dwz.err; status=$?; then
+    true
+fi
+
+[ $status -eq 1 ]
+
+grep -q "Cannot use implicit file in combination with -o option" dwz.err
+
+rm -f a.out dwz.err

                 reply	other threads:[~2021-03-22  5:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210322054323.GA2676@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.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).