summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-06-04 15:22:40 -0700
committerBrian Anderson <banderson@mozilla.com>2012-06-04 15:22:40 -0700
commit2d0e7cd272136f12f8c07cafe57df408d37ada6f (patch)
tree8eaaa422b162f8d57ed3da90ffd2186bc4b9352c /src/libcore
parent6e0085210c54150f794d20791b2e9c1fda6049fc (diff)
downloadrust-2d0e7cd272136f12f8c07cafe57df408d37ada6f.tar.gz
rust-2d0e7cd272136f12f8c07cafe57df408d37ada6f.zip
core: Don't allow radix 1 in uint::to_str
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/uint-template.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index 0904a6d9382..6e513b2f5e2 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -95,9 +95,15 @@ fn from_str_radix(buf: str, radix: u64) -> option<u64> {
     };
 }
 
-#[doc = "Convert to a string in a given base"]
+#[doc = "
+Convert to a string in a given base
+
+# Failure
+
+Fails if `radix` < 2 or `radix` > 16
+"]
 fn to_str(num: T, radix: uint) -> str {
-    assert (0u < radix && radix <= 16u);
+    assert (1u < radix && radix <= 16u);
     let mut n = num;
     let radix = radix as T;
     fn digit(n: T) -> u8 {
@@ -167,3 +173,17 @@ fn test_parse_buf() {
     assert parse_buf(str::bytes("Z"), 10u) == none;
     assert parse_buf(str::bytes("_"), 2u) == none;
 }
+
+#[test]
+#[should_fail]
+#[ignore(cfg(target_os = "win32"))]
+fn to_str_radix1() {
+    uint::to_str(100u, 1u);
+}
+
+#[test]
+#[should_fail]
+#[ignore(cfg(target_os = "win32"))]
+fn to_str_radix17() {
+    uint::to_str(100u, 17u);
+}