Skip to content

Commit 7ccd240

Browse files
mbrubeckbrson
authored andcommitted
---
yaml --- r: 6051 b: refs/heads/master c: 7080ac1 h: refs/heads/master i: 6049: 2f9338f 6047: c082c23 v: v3
1 parent fe9d6ae commit 7ccd240

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8c51d4b002b2743fd50bc715429265aaaf482762
2+
refs/heads/master: 7080ac15fb13c472985da692ca92c4a48b1f5575

trunk/src/lib/int.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,18 @@ fn parse_buf(buf: [u8], radix: uint) -> int {
103103
fail;
104104
}
105105
let i = vec::len::<u8>(buf) - 1u;
106+
let start = 0u;
106107
let power = 1;
108+
107109
if buf[0] == ('-' as u8) {
108110
power = -1;
109-
i -= 1u;
111+
start = 1u;
110112
}
111113
let n = 0;
112114
while true {
113115
n += (buf[i] - ('0' as u8) as int) * power;
114116
power *= radix as int;
115-
if i == 0u { ret n; }
117+
if i <= start { ret n; }
116118
i -= 1u;
117119
}
118120
fail;

trunk/src/test/stdtest/int.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ use std;
33
import std::int;
44
import std::str::eq;
55

6+
#[test]
7+
fn test_from_str() {
8+
assert(int::from_str("0") == 0);
9+
assert(int::from_str("3") == 3);
10+
assert(int::from_str("10") == 10);
11+
assert(int::from_str("123456789") == 123456789);
12+
assert(int::from_str("00100") == 100);
13+
14+
assert(int::from_str("-1") == -1);
15+
assert(int::from_str("-3") == -3);
16+
assert(int::from_str("-10") == -10);
17+
assert(int::from_str("-123456789") == -123456789);
18+
assert(int::from_str("-00100") == -100);
19+
}
20+
621
#[test]
722
fn test_to_str() {
823
assert (eq(int::to_str(0, 10u), "0"));
@@ -29,4 +44,4 @@ fn test_overflows() {
2944
assert (int::max_value() > 0);
3045
assert (int::min_value() <= 0);
3146
assert (int::min_value() + int::max_value() + 1 == 0);
32-
}
47+
}

0 commit comments

Comments
 (0)