Improve buffer handling when interfacing with native layer. Fix #431
This commit is contained in:
parent
c4409241b6
commit
c5c2a4ab90
|
@ -29,7 +29,7 @@ impl super::ClipboardManager for MacClipboardManager {
|
|||
fn get_clipboard(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [c_char; 2000] = [0; 2000];
|
||||
let res = get_clipboard(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let res = get_clipboard(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = CStr::from_ptr(buffer.as_ptr());
|
||||
|
|
|
@ -35,7 +35,7 @@ impl super::ClipboardManager for WindowsClipboardManager {
|
|||
fn get_clipboard(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [u16; 2000] = [0; 2000];
|
||||
let res = get_clipboard(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let res = get_clipboard(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = U16CString::from_ptr_str(buffer.as_ptr());
|
||||
|
|
|
@ -29,8 +29,8 @@ pub struct LinuxSystemManager {}
|
|||
impl super::SystemManager for LinuxSystemManager {
|
||||
fn get_current_window_title(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [c_char; 100] = [0; 100];
|
||||
let res = get_active_window_name(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let mut buffer: [c_char; 256] = [0; 256];
|
||||
let res = get_active_window_name(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = CStr::from_ptr(buffer.as_ptr());
|
||||
|
@ -47,8 +47,8 @@ impl super::SystemManager for LinuxSystemManager {
|
|||
|
||||
fn get_current_window_class(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [c_char; 100] = [0; 100];
|
||||
let res = get_active_window_class(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let mut buffer: [c_char; 256] = [0; 256];
|
||||
let res = get_active_window_class(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = CStr::from_ptr(buffer.as_ptr());
|
||||
|
@ -65,8 +65,8 @@ impl super::SystemManager for LinuxSystemManager {
|
|||
|
||||
fn get_current_window_executable(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [c_char; 100] = [0; 100];
|
||||
let res = get_active_window_executable(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let mut buffer: [c_char; 256] = [0; 256];
|
||||
let res = get_active_window_executable(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = CStr::from_ptr(buffer.as_ptr());
|
||||
|
|
|
@ -33,8 +33,8 @@ impl super::SystemManager for MacSystemManager {
|
|||
|
||||
fn get_current_window_class(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [c_char; 250] = [0; 250];
|
||||
let res = get_active_app_identifier(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let mut buffer: [c_char; 256] = [0; 256];
|
||||
let res = get_active_app_identifier(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = CStr::from_ptr(buffer.as_ptr());
|
||||
|
@ -51,8 +51,8 @@ impl super::SystemManager for MacSystemManager {
|
|||
|
||||
fn get_current_window_executable(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [c_char; 250] = [0; 250];
|
||||
let res = get_active_app_bundle(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let mut buffer: [c_char; 256] = [0; 256];
|
||||
let res = get_active_app_bundle(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = CStr::from_ptr(buffer.as_ptr());
|
||||
|
|
|
@ -31,8 +31,8 @@ impl WindowsSystemManager {
|
|||
impl super::SystemManager for WindowsSystemManager {
|
||||
fn get_current_window_title(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [u16; 100] = [0; 100];
|
||||
let res = get_active_window_name(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let mut buffer: [u16; 256] = [0; 256];
|
||||
let res = get_active_window_name(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = U16CString::from_ptr_str(buffer.as_ptr());
|
||||
|
@ -51,8 +51,8 @@ impl super::SystemManager for WindowsSystemManager {
|
|||
|
||||
fn get_current_window_executable(&self) -> Option<String> {
|
||||
unsafe {
|
||||
let mut buffer: [u16; 250] = [0; 250];
|
||||
let res = get_active_window_executable(buffer.as_mut_ptr(), buffer.len() as i32);
|
||||
let mut buffer: [u16; 256] = [0; 256];
|
||||
let res = get_active_window_executable(buffer.as_mut_ptr(), (buffer.len() - 1) as i32);
|
||||
|
||||
if res > 0 {
|
||||
let c_string = U16CString::from_ptr_str(buffer.as_ptr());
|
||||
|
|
Loading…
Reference in New Issue
Block a user