From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/8] [gdb/rust] Fix literal truncation
Date: Mon, 23 May 2022 13:05:16 +0200 [thread overview]
Message-ID: <20220523110518.2447-6-tdevries@suse.de> (raw)
In-Reply-To: <20220523110518.2447-1-tdevries@suse.de>
Make sure we error out on overflow instead of truncating in all cases.
I've used as overflow string: "Integer literal is too large", based
on what I found at
<rust-lang/rust>/src/test/ui/parser/int-literal-too-large-span.rs
but perhaps someone has a better idea.
Tested on x86_64-linux, with a build with --enable-targets=all.
---
gdb/rust-parse.c | 5 ++++-
gdb/testsuite/gdb.base/parse_number.exp | 5 +++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 7d7d882872c..836f49108f8 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -1024,7 +1024,10 @@ rust_parser::lex_number ()
}
}
- value = strtoulst (number.c_str () + offset, NULL, radix);
+ const char *trailer;
+ value = strtoulst (number.c_str () + offset, &trailer, radix);
+ if (*trailer != '\0')
+ error ("Integer literal is too large");
if (implicit_i32 && value >= ((uint64_t) 1) << 31)
type = get_type ("i64");
diff --git a/gdb/testsuite/gdb.base/parse_number.exp b/gdb/testsuite/gdb.base/parse_number.exp
index f9782115b7c..4189ccaf92c 100644
--- a/gdb/testsuite/gdb.base/parse_number.exp
+++ b/gdb/testsuite/gdb.base/parse_number.exp
@@ -113,8 +113,7 @@ proc parse_number { lang n } {
return [list "i64" $n]
} else {
# Overflow.
- # Some truncated value, should be re_overflow.
- return [list i64 $any]
+ return [list $re_overflow $re_overflow]
}
} elseif { $lang == "d" } {
if { [fits_in_type $n 32 s] } {
@@ -274,6 +273,8 @@ proc test_parse_numbers {arch} {
set re_overflow "Overflow on numeric constant\\."
} elseif { $lang == "ada" } {
set re_overflow "Integer literal out of range"
+ } elseif { $lang == "rust" } {
+ set re_overflow "Integer literal is too large"
} else {
set re_overflow "Numeric constant too large\\."
}
--
2.35.3
next prev parent reply other threads:[~2022-05-23 11:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-23 11:05 [PATCH 1/8] [gdb/testsuite] Test more values in gdb.base/parse_numbers.exp Tom de Vries
2022-05-23 11:05 ` [PATCH 2/8] [gdb/c] Fix type of 2147483648 and literal truncation Tom de Vries
2022-05-23 11:05 ` [PATCH 3/8] [gdb/fortran] Fix " Tom de Vries
2022-05-23 11:05 ` [PATCH 4/8] [gdb/go] " Tom de Vries
2022-05-23 11:05 ` [PATCH 5/8] [gdb/pascal] " Tom de Vries
2022-05-23 11:05 ` Tom de Vries [this message]
2022-05-26 17:17 ` [PATCH 6/8] [gdb/rust] " Tom Tromey
2022-06-07 9:29 ` Tom de Vries
2022-05-23 11:05 ` [PATCH 7/8] [gdb/m2] Fix UB and " Tom de Vries
2022-05-23 11:05 ` [PATCH 8/8] [gdb/ada] Fix " Tom de Vries
2022-06-04 11:20 ` [PATCH 1/8] [gdb/testsuite] Test more values in gdb.base/parse_numbers.exp Tom de Vries
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=20220523110518.2447-6-tdevries@suse.de \
--to=tdevries@suse.de \
--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).