mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-07 12:33:14 +00:00
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.
This commit is contained in:
commit
d89ff7eef9
@ -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);
|
||||
}
|
||||
@ -2825,6 +2825,13 @@ mod tests {
|
||||
assert!(!" _ ".is_whitespace());
|
||||
}
|
||||
|
||||
#[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";
|
||||
|
Loading…
Reference in New Issue
Block a user