about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2013-08-04 16:10:19 -0400
committerSteven Fackler <sfackler@gmail.com>2013-08-04 16:19:40 -0400
commit147c4fd81b25afe8a0b3ef50987d916370d7133b (patch)
tree1cc875ac2a468f26684e1e212f215a25840036df /src/libstd
parent93432a2c2f244f46c8c60c3988483b20def990b7 (diff)
downloadrust-147c4fd81b25afe8a0b3ef50987d916370d7133b.tar.gz
rust-147c4fd81b25afe8a0b3ef50987d916370d7133b.zip
Fixed str::raw::push_byte
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')
-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 c30888529be..4398e414cda 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -878,7 +878,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);
     }
@@ -2802,6 +2802,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)};