public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] sim: run: fix crash in argc==0 error situation
@ 2021-11-15  8:37 Mike Frysinger
  2021-11-15  8:37 ` [PATCH 2/2] sim: cris: make error message test a little more flexible Mike Frysinger
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2021-11-15  8:37 UTC (permalink / raw)
  To: gdb-patches

The new argv processing code assumed that we were always passed a
command line.  If we weren't, make sure we don't crash before we
get a chance to output an error message about incorrect usage.
---
 sim/common/sim-options.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index ee7d11fb6925..17e550e55577 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -615,16 +615,26 @@ sim_parse_args (SIM_DESC sd, char * const *argv)
 	{
 	  if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
 	    {
-	      char **new_argv = dupargv (argv + optind);
+	      char **new_argv;
 
-	      STATE_PROG_FILE (sd) = xstrdup (argv[optind]);
-	      if (STATE_PROG_ARGV0 (sd) != NULL)
-		{
-		  free (new_argv[0]);
-		  new_argv[0] = xstrdup (STATE_PROG_ARGV0 (sd));
-		}
+	      free (STATE_PROG_FILE (sd));
+	      STATE_PROG_FILE (sd) = NULL;
+
+	      new_argv = dupargv (argv + optind);
 	      freeargv (STATE_PROG_ARGV (sd));
 	      STATE_PROG_ARGV (sd) = new_argv;
+
+	      /* Skip steps when argc == 0.  */
+	      if (argv[optind] != NULL)
+		{
+		  STATE_PROG_FILE (sd) = xstrdup (argv[optind]);
+
+		  if (STATE_PROG_ARGV0 (sd) != NULL)
+		    {
+		      free (new_argv[0]);
+		      new_argv[0] = xstrdup (STATE_PROG_ARGV0 (sd));
+		    }
+		}
 	    }
 	  break;
 	}
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] sim: cris: make error message test a little more flexible
  2021-11-15  8:37 [PATCH 1/2] sim: run: fix crash in argc==0 error situation Mike Frysinger
@ 2021-11-15  8:37 ` Mike Frysinger
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2021-11-15  8:37 UTC (permalink / raw)
  To: gdb-patches

The point of this test is to just make sure the usage text is shown,
not the exact details of the usage text.  So shorten the output test
to match the beginning.  This fixes breakage when the output changed
slightly to include [--].
---
 sim/testsuite/cris/asm/opterr3.ms | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sim/testsuite/cris/asm/opterr3.ms b/sim/testsuite/cris/asm/opterr3.ms
index 8d602be2e6c3..b3279f0198a2 100644
--- a/sim/testsuite/cris/asm/opterr3.ms
+++ b/sim/testsuite/cris/asm/opterr3.ms
@@ -2,7 +2,7 @@
 # ld: -N --oformat binary --section-start=.text=0x10000000
 # sim: --cris-naked --memory-mapfile
 # xerror:
-# output: Usage: run \[options\] program \[program args\]\n*\n
+# output: Usage: run *\n*\n
 # progopts: --memory-region 0x10000000,0x1000
  .include "bare3.ms"
 
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-15  8:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15  8:37 [PATCH 1/2] sim: run: fix crash in argc==0 error situation Mike Frysinger
2021-11-15  8:37 ` [PATCH 2/2] sim: cris: make error message test a little more flexible Mike Frysinger

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