Skip to content

Commit c8dea1c

Browse files
committed
Update: config travis
1 parent b61f5d8 commit c8dea1c

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: rust
2+
3+
rust:
4+
- 1.40.0
5+
- stable
6+
- beta
7+
- nightly
8+
9+
script:
10+
- cargo build --verbose --all --all-features
11+
- cargo test --verbose --all --all-features

src/bin/mstsc-rs.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,31 @@ pub unsafe fn transmute_vec<S, T>(mut vec: Vec<S>) -> Vec<T> {
7676
/// Copy a bitmap event into the buffer
7777
/// This function use unsafe copy
7878
/// to accelerate data transfer
79-
fn fast_bitmap_transfer(buffer: &mut Vec<u32>, width: usize, bitmap: BitmapEvent) {
80-
let bitmap_dest_left = bitmap.dest_left;
81-
let bitmap_dest_right = bitmap.dest_right;
82-
let bitmap_dest_bottom = bitmap.dest_bottom;
83-
let bitmap_dest_top = bitmap.dest_top;
84-
let bitmap_width = bitmap.width;
85-
86-
let data = match bitmap.decompress() {
87-
Ok(e) => e,
88-
Err(_) => {
89-
println!("Error during decompression");
90-
return;
91-
}
92-
};
79+
fn fast_bitmap_transfer(buffer: &mut Vec<u32>, width: usize, bitmap: BitmapEvent) -> RdpResult<()>{
80+
let bitmap_dest_left = bitmap.dest_left as usize;
81+
let bitmap_dest_right = bitmap.dest_right as usize;
82+
let bitmap_dest_bottom = bitmap.dest_bottom as usize;
83+
let bitmap_dest_top = bitmap.dest_top as usize;
84+
let bitmap_width = bitmap.width as usize;
85+
86+
let data = bitmap.decompress()?;
9387

9488
// Use some unsafe method to faster
95-
// data transfert between buffers
89+
// data transfer between buffers
9690
unsafe {
9791
let data_aligned :Vec<u32> = transmute_vec(data);
98-
for i in 0..((bitmap_dest_bottom - bitmap_dest_top + 1) as u16) {
99-
let dest_i = (i + bitmap_dest_top) as usize * width as usize + bitmap_dest_left as usize;
100-
copy_nonoverlapping(data_aligned.as_ptr().offset((i * bitmap_width) as isize), buffer.as_mut_ptr().offset(dest_i as isize), (bitmap_dest_right - bitmap_dest_left + 1) as usize)
92+
for i in 0..(bitmap_dest_bottom - bitmap_dest_top + 1) {
93+
let dest_i = (i + bitmap_dest_top) * width + bitmap_dest_left;
94+
let src_i = i * bitmap_width;
95+
let count = (bitmap_dest_right - bitmap_dest_left + 1);
96+
if dest_i > buffer.len() || dest_i + count > buffer.len() || src_i > data_aligned.len() || src_i + count > data_aligned.len() {
97+
return Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidSize, "Image have invalide size")))
98+
}
99+
copy_nonoverlapping(data_aligned.as_ptr().offset((src_i) as isize), buffer.as_mut_ptr().offset(dest_i as isize), count)
101100
}
102101
}
103102

103+
Ok(())
104104
}
105105

106106
/// Translate minifb mouse to rdp-rs
@@ -116,6 +116,7 @@ fn get_rdp_pointer_down(window: &Window) -> PointerButton {
116116
}
117117
}
118118

119+
/// Translate minifb key to scancode
119120
fn to_scancode(key: Key) -> u16 {
120121
match key {
121122
Key::Escape => 0x0001,

src/core/global.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -899,28 +899,28 @@ mod test {
899899
#[test]
900900
fn test_read_synchronize_pdu() {
901901
let mut stream = Cursor::new(vec![22, 0, 23, 0, 234, 3, 234, 3, 1, 0, 0, 2, 22, 0, 31, 0, 0, 0, 1, 0, 0, 0]);
902-
let mut global = Client::new(0,0, 800, 600, KeyboardLayout::US);
902+
let mut global = Client::new(0,0, 800, 600, KeyboardLayout::US, "foo");
903903
assert!(global.read_synchronize_pdu(&mut stream).unwrap())
904904
}
905905

906906
#[test]
907907
fn test_read_control_cooperate_pdu() {
908908
let mut stream = Cursor::new(vec![26, 0, 23, 0, 234, 3, 234, 3, 1, 0, 0, 2, 26, 0, 20, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0]);
909-
let mut global = Client::new(0,0, 800, 600, KeyboardLayout::US);
909+
let mut global = Client::new(0,0, 800, 600, KeyboardLayout::US, "foo");
910910
assert!(global.read_control_pdu(&mut stream, Action::CtrlactionCooperate).unwrap())
911911
}
912912

913913
#[test]
914914
fn test_read_control_granted_pdu() {
915915
let mut stream = Cursor::new(vec![26, 0, 23, 0, 234, 3, 234, 3, 1, 0, 0, 2, 26, 0, 20, 0, 0, 0, 2, 0, 236, 3, 234, 3, 0, 0]);
916-
let mut global = Client::new(0,0, 800, 600, KeyboardLayout::US);
916+
let mut global = Client::new(0,0, 800, 600, KeyboardLayout::US, "foo");
917917
assert!(global.read_control_pdu(&mut stream, Action::CtrlactionGrantedControl).unwrap())
918918
}
919919

920920
#[test]
921921
fn test_read_font_map_pdu() {
922922
let mut stream = Cursor::new(vec![26, 0, 23, 0, 234, 3, 234, 3, 1, 0, 0, 2, 26, 0, 40, 0, 0, 0, 0, 0, 0, 0, 3, 0, 4, 0]);
923-
let mut global = Client::new(0,0, 800, 600, KeyboardLayout::US);
923+
let mut global = Client::new(0,0, 800, 600, KeyboardLayout::US, "foo");
924924
assert!(global.read_font_map_pdu(&mut stream).unwrap())
925925
}
926926
}

0 commit comments

Comments
 (0)