Skip to content

Commit d89ff7e

Browse files
committed
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.
2 parents c2bacd2 + 147c4fd commit d89ff7e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libstd/str.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ pub mod raw {
902902
let new_len = s.len() + 1;
903903
s.reserve_at_least(new_len);
904904
do s.as_mut_buf |buf, len| {
905-
*ptr::mut_offset(buf, len as int) = b;
905+
*ptr::mut_offset(buf, (len-1) as int) = b;
906906
}
907907
set_len(&mut *s, new_len);
908908
}
@@ -2825,6 +2825,13 @@ mod tests {
28252825
assert!(!" _ ".is_whitespace());
28262826
}
28272827

2828+
#[test]
2829+
fn test_push_byte() {
2830+
let mut s = ~"ABC";
2831+
unsafe{raw::push_byte(&mut s, 'D' as u8)};
2832+
assert_eq!(s, ~"ABCD");
2833+
}
2834+
28282835
#[test]
28292836
fn test_shift_byte() {
28302837
let mut s = ~"ABC";

0 commit comments

Comments
 (0)