Skip to content

Commit fef8314

Browse files
committed
stdlib: Real fix for _uint.parse_buf().
1 parent 73044b3 commit fef8314

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib/_uint.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,22 @@ fn next_power_of_two(uint n) -> uint {
3434
}
3535

3636
fn parse_buf(vec[u8] buf, uint radix) -> uint {
37+
if (_vec.len[u8](buf) == 0u) {
38+
log_err "parse_buf(): buf is empty";
39+
fail;
40+
}
41+
3742
auto i = _vec.len[u8](buf) - 1u;
3843
auto power = 1u;
3944
auto n = 0u;
4045
while (true) {
4146
n += (((buf.(i)) - ('0' as u8)) as uint) * power;
4247
power *= radix;
4348
if (i == 0u) { ret n; }
49+
i -= 1u;
4450
}
51+
52+
fail;
4553
}
4654

4755
fn to_str(uint num, uint radix) -> str

0 commit comments

Comments
 (0)