graydon/rust — Issue #1102: int::from_str("-1") == -253 and other bugs
Author: mbrubeck
Created: 2011-10-30 05:13:40+00:00
State: open

int::from_str returns bad results for strings that start with "-" signs, because it adjust its character position in the wrong direction. Examples:

```
assert(int::from_str("-1") == -253);
assert(int::from_str("-3") == -253);
assert(int::from_str("-10") == -2531);
assert(int::from_str("-x") == -253);
assert(int::from_str("-0x") == -2530);
```

It also returns bad results for any strings with non-numeric characters:

```
assert(int::from_str("x") == 72);
```

In addition, int::parse_buf is broken for any radix greater than 10:

```
assert(int::parse_buf(['a' as u8], 16u) == 49);
```

Most or all of the same bugs apply to the `uint` module too.

While we're here, would it be better for these methods to return option::t instead of failing on bad input?