]> git.lizzy.rs Git - rust.git/commitdiff
Stop parsing "-" as integer, fixes #22745
authorMichał Krasnoborski <mkrdln@gmail.com>
Tue, 24 Feb 2015 01:40:32 +0000 (02:40 +0100)
committerMichał Krasnoborski <mkrdln@gmail.com>
Tue, 24 Feb 2015 05:04:49 +0000 (06:04 +0100)
src/libcore/num/mod.rs
src/libcoretest/num/mod.rs

index 7612469c8088bbfe3c30579d02e28f48aa4482fd..b1039f79f23de1989343683d2d4cc99cd528a906 100644 (file)
@@ -1672,6 +1672,7 @@ fn from_str_radix(src: &str, radix: u32)
                 let is_signed_ty = (0 as $T) > Int::min_value();
 
                 match src.slice_shift_char() {
+                    Some(('-', "")) => Err(PIE { kind: Empty }),
                     Some(('-', src)) if is_signed_ty => {
                         // The number is negative
                         let mut result = 0;
index 2c6efc0040fae82bb3adb7247ae9506e7ed6b972..1199fd0106850702c0edd8257fc300d7e21d3e79 100644 (file)
@@ -122,4 +122,9 @@ fn test_int_from_str_overflow() {
         assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(i64_val));
         assert_eq!("-9223372036854775809".parse::<i64>().ok(), None);
     }
+
+    #[test]
+    test_int_from_minus_sign() {
+        assert_eq!("-".parse::<i32>().ok(), None);
+    }
 }