mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-23 03:29:47 +08:00
[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:
@ -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");
|
||||
|
||||
|
@ -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\\."
|
||||
}
|
||||
|
Reference in New Issue
Block a user