about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-04-27 11:59:22 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-04-27 11:59:22 -0700
commitfef8314c2e018d2e35c8bd91d3181de038e44de2 (patch)
tree3ef92bb9b095b8dcfab6fe97e478f65529fbb002
parent73044b3455b7586557eabbd249023d0a363401d0 (diff)
downloadrust-fef8314c2e018d2e35c8bd91d3181de038e44de2.tar.gz
rust-fef8314c2e018d2e35c8bd91d3181de038e44de2.zip
stdlib: Real fix for _uint.parse_buf().
-rw-r--r--src/lib/_uint.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/_uint.rs b/src/lib/_uint.rs
index ce01dabffd4..97108c9082b 100644
--- a/src/lib/_uint.rs
+++ b/src/lib/_uint.rs
@@ -34,6 +34,11 @@ fn next_power_of_two(uint n) -> uint {
 }
 
 fn parse_buf(vec[u8] buf, uint radix) -> uint {
+    if (_vec.len[u8](buf) == 0u) {
+        log_err "parse_buf(): buf is empty";
+        fail;
+    }
+
     auto i = _vec.len[u8](buf) - 1u;
     auto power = 1u;
     auto n = 0u;
@@ -41,7 +46,10 @@ fn parse_buf(vec[u8] buf, uint radix) -> uint {
         n += (((buf.(i)) - ('0' as u8)) as uint) * power;
         power *= radix;
         if (i == 0u) { ret n; }
+        i -= 1u;
     }
+
+    fail;
 }
 
 fn to_str(uint num, uint radix) -> str