aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-parse.c
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2022-06-04 13:17:33 +0200
committerTom de Vries <tdevries@suse.de>2022-06-04 13:17:33 +0200
commit1390b65a1b93f75cdd4165f190b4a95b93add66e (patch)
tree8a9a65061da32d5197e37ec32f2338d74e3aab16 /gdb/rust-parse.c
parent7af9baa9faead8155e4459104c30cb1b6a15180e (diff)
downloadbinutils-1390b65a1b93f75cdd4165f190b4a95b93add66e.zip
binutils-1390b65a1b93f75cdd4165f190b4a95b93add66e.tar.gz
binutils-1390b65a1b93f75cdd4165f190b4a95b93add66e.tar.bz2
[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.
Diffstat (limited to 'gdb/rust-parse.c')
-rw-r--r--gdb/rust-parse.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 7d7d882..836f491 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");