about summary refs log tree commit diff
path: root/src/libstd/str.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-05 08:10:55 -0700
committerbors <bors@rust-lang.org>2013-08-05 08:10:55 -0700
commitd89ff7eef969aee6b493bc846b64d68358fafbcd (patch)
tree2742ff71abc4080bc8c37cf7cf3863666714fb72 /src/libstd/str.rs
parentc2bacd2e803c8432d9ad051c39c7e3b3f70f193e (diff)
parent147c4fd81b25afe8a0b3ef50987d916370d7133b (diff)
downloadrust-d89ff7eef969aee6b493bc846b64d68358fafbcd.tar.gz
rust-d89ff7eef969aee6b493bc846b64d68358fafbcd.zip
auto merge of #8289 : sfackler/rust/push_byte, r=erickt
It was previously pushing the byte on top of the string's null
terminator. I added a test to make sure it doesn't break in the future.
Diffstat (limited to 'src/libstd/str.rs')
-rw-r--r--src/libstd/str.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 5c6895fea43..1a913fb4e99 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -902,7 +902,7 @@ pub mod raw {
         let new_len = s.len() + 1;
         s.reserve_at_least(new_len);
         do s.as_mut_buf |buf, len| {
-            *ptr::mut_offset(buf, len as int) = b;
+            *ptr::mut_offset(buf, (len-1) as int) = b;
         }
         set_len(&mut *s, new_len);
     }
@@ -2826,6 +2826,13 @@ mod tests {
     }
 
     #[test]
+    fn test_push_byte() {
+        let mut s = ~"ABC";
+        unsafe{raw::push_byte(&mut s, 'D' as u8)};
+        assert_eq!(s, ~"ABCD");
+    }
+
+    #[test]
     fn test_shift_byte() {
         let mut s = ~"ABC";
         let b = unsafe{raw::shift_byte(&mut s)};