Fix for an underflow on some type conversions (#1715)

This commit is contained in:
Zac Pullar-Strecker 2018-11-25 10:08:02 +13:00 committed by GitHub
parent 0d47cd25b9
commit 742a6b48a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View File

@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Extra padding is not evenly spread around the terminal by default anymore
### Fixed
- Fixed a bad type conversion which could cause underflow on a window resize
## Version 0.2.3
### Fixed

View File

@ -865,8 +865,8 @@ impl SizeInfo {
let line = Line(y.saturating_sub(self.padding_y as usize) / (self.cell_height as usize));
Point {
line: min(line, self.lines() - 1),
col: min(col, self.cols() - 1)
line: min(line, Line(self.lines().saturating_sub(1))),
col: min(col, Column(self.cols().saturating_sub(1)))
}
}
}

View File

@ -19,6 +19,7 @@ use std::os::windows::io::{FromRawHandle, IntoRawHandle};
use std::os::windows::fs::OpenOptionsExt;
use std::env;
use std::cell::UnsafeCell;
use std::u16;
use dunce::canonicalize;
use mio;
@ -276,8 +277,9 @@ impl<'a> EventedReadWrite for Pty<'a, NamedPipe, NamedPipe> {
impl<'a> OnResize for Winpty<'a> {
fn on_resize(&mut self, sizeinfo: &SizeInfo) {
if sizeinfo.cols().0 > 0 && sizeinfo.lines().0 > 0 {
self.set_size(sizeinfo.cols().0, sizeinfo.lines().0)
let (cols, lines) = (sizeinfo.cols().0, sizeinfo.lines().0);
if cols > 0 && cols <= u16::MAX as usize && lines > 0 && lines <= u16::MAX as usize {
self.set_size(cols as u16, lines as u16)
.unwrap_or_else(|_| info!("Unable to set winpty size, did it die?"));
}
}

View File

@ -201,12 +201,12 @@ impl<'a, 'b> Winpty<'a> {
/// Change the size of the Windows console window.
///
/// cols & rows MUST be greater than 0
pub fn set_size(&mut self, cols: usize, rows: usize) -> Result<(), Err> {
pub fn set_size(&mut self, cols: u16, rows: u16) -> Result<(), Err> {
assert!(cols > 0 && rows > 0);
let mut err = null_mut() as *mut winpty_error_t;
unsafe {
winpty_set_size(self.0, cols as i32, rows as i32, &mut err);
winpty_set_size(self.0, i32::from(cols), i32::from(rows), &mut err);
}
if let Some(err) = check_err(err) {