[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
<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.
This commit is contained in:
Tom de Vries
2022-06-04 13:17:33 +02:00
parent 7af9baa9fa
commit 1390b65a1b
2 changed files with 7 additions and 3 deletions

View File

@ -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");

View File

@ -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\\."
}