Fix Rust lexer buglet
authorTom Tromey <tromey@adacore.com>
Tue, 9 Apr 2019 19:19:28 +0000 (13:19 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 9 Apr 2019 19:21:13 +0000 (13:21 -0600)
PR rust/24414 points out that the Rust lexer uses strtoul when lexing
an integer, and that this can give the wrong results in some
situations.

This patch changes it to use strtoulst, like most of the rest of gdb.
It also adds a self test.

Tested on x86-64 Fedora 29 using an i686 build.

gdb/ChangeLog
2019-04-09  Ivan Begert  <ivanbegert@gmail.com>
    Tom Tromey  <tromey@adacore.com>

PR rust/24414:
* rust-exp.y (rust_parser::lex_number): Use strtoulst.
(rust_lex_int_test): Change "value" to be LONGEST.
(rust_lex_tests): Add test for long integer literal.

gdb/ChangeLog
gdb/rust-exp.y

index 6ee8d05764d172253738465503da97b18ccf55b1..f9b9e88b517dd44b52c068557406b4957311250c 100644 (file)
@@ -1,3 +1,11 @@
+2019-04-09  Ivan Begert  <ivanbegert@gmail.com>
+           Tom Tromey  <tromey@adacore.com>
+
+       PR rust/24414:
+       * rust-exp.y (rust_parser::lex_number): Use strtoulst.
+       (rust_lex_int_test): Change "value" to be LONGEST.
+       (rust_lex_tests): Add test for long integer literal.
+
 2019-04-09  Tom Tromey  <tromey@adacore.com>
 
        * remote.c (remote_target::remote_add_inferior): Change fake_pid_p
index 2be2532eb8457cb03cae1ea802d2f0ca2a6734ee..15932638397d0854e41f2b73b359147076925189 100644 (file)
@@ -1610,7 +1610,7 @@ rust_parser::lex_number (YYSTYPE *lvalp)
            }
        }
 
-      value = strtoul (number.c_str () + offset, NULL, radix);
+      value = strtoulst (number.c_str () + offset, NULL, radix);
       if (implicit_i32 && value >= ((uint64_t) 1) << 31)
        type = get_type ("i64");
 
@@ -2603,7 +2603,8 @@ rust_lex_test_one (rust_parser *parser, const char *input, int expected)
 /* Test that INPUT lexes as the integer VALUE.  */
 
 static void
-rust_lex_int_test (rust_parser *parser, const char *input, int value, int kind)
+rust_lex_int_test (rust_parser *parser, const char *input,
+                  LONGEST value, int kind)
 {
   RUSTSTYPE result = rust_lex_test_one (parser, input, kind);
   SELF_CHECK (result.typed_val_int.val == value);
@@ -2781,6 +2782,7 @@ rust_lex_tests (void)
   rust_lex_int_test (&parser, "0x1_f", 0x1f, INTEGER);
   rust_lex_int_test (&parser, "0b1_101011__", 0x6b, INTEGER);
   rust_lex_int_test (&parser, "0o001177i64", 639, INTEGER);
+  rust_lex_int_test (&parser, "0x123456789u64", 0x123456789ull, INTEGER);
 
   rust_lex_test_trailing_dot (&parser);
 
This page took 0.028691 seconds and 4 git commands to generate.