public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Don't allow implicit file argument in combination with -o
@ 2021-03-22  5:43 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-03-22  5:43 UTC (permalink / raw)
  To: dwz, jakub, mark

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-22  5:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22  5:43 [PATCH] Don't allow implicit file argument in combination with -o Tom de Vries

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