public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [pushed] Fix crash in Rust expression parser
Date: Mon,  1 May 2023 10:16:41 -0600	[thread overview]
Message-ID: <20230501161642.2435886-1-tromey@adacore.com> (raw)

A user found that an array expression with just a single value (like
"[23]") caused the Rust expression parser to crash.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30410
---
 gdb/rust-parse.c                | 4 ++--
 gdb/testsuite/gdb.rust/expr.exp | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 6c7922de9c7..648e48dda40 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -1190,7 +1190,7 @@ rust_parser::parse_array ()
       result = make_operation<rust_array_operation> (std::move (expr),
 						     std::move (rhs));
     }
-  else if (current_token == ',')
+  else if (current_token == ',' || current_token == ']')
     {
       std::vector<operation_up> ops;
       ops.push_back (std::move (expr));
@@ -1205,7 +1205,7 @@ rust_parser::parse_array ()
       int len = ops.size () - 1;
       result = make_operation<array_operation> (0, len, std::move (ops));
     }
-  else if (current_token != ']')
+  else
     error (_("',', ';', or ']' expected"));
 
   require (']');
diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
index 4a0a48ade62..908d1a3680b 100644
--- a/gdb/testsuite/gdb.rust/expr.exp
+++ b/gdb/testsuite/gdb.rust/expr.exp
@@ -113,6 +113,7 @@ gdb_test "ptype \[1,2,3,4\]" "type = \\\[i32; 4\\\]"
 gdb_test "print \[mut 1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"
 gdb_test "print \[1,2 3" "',' or ']' expected"
 gdb_test "print \[1 2" "',', ';', or ']' expected"
+gdb_test "print \[23\]" " = \\\[23\\\]"
 
 gdb_test "print b\"hi rust\"" " = b\"hi rust\""
 # This isn't rusty syntax yet, but that's another bug -- this is just
-- 
2.39.1


                 reply	other threads:[~2023-05-01 16:16 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=20230501161642.2435886-1-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.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).