From 1390b65a1b93f75cdd4165f190b4a95b93add66e Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Sat, 4 Jun 2022 13:17:33 +0200 Subject: [PATCH] [gdb/rust] Fix literal truncation 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 /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.30.2