mirror of
https://github.com/denoland/deno.git
synced 2024-11-27 16:10:57 -05:00
add over/under-flow protections to calculation
This commit is contained in:
parent
5c58cb2bf5
commit
0cee79e4bf
1 changed files with 14 additions and 4 deletions
|
@ -351,10 +351,20 @@ fn console_size_from_fd(
|
||||||
{
|
{
|
||||||
return Err(Error::last_os_error());
|
return Err(Error::last_os_error());
|
||||||
}
|
}
|
||||||
Ok(ConsoleSize {
|
|
||||||
cols: bufinfo.srWindow.Right as u32 - bufinfo.srWindow.Left as u32 + 1,
|
// calculate the size of the visible window
|
||||||
rows: bufinfo.srWindow.Bottom as u32 - bufinfo.srWindow.Top as u32 + 1,
|
// * use over/under-flow protections b/c MSDN docs only imply that srWindow components are all non-negative
|
||||||
})
|
// * ref: <https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str> @@ <https://archive.is/sfjnm>
|
||||||
|
let cols = std::cmp::max(
|
||||||
|
bufinfo.srWindow.Right as i32 - bufinfo.srWindow.Left as i32 + 1,
|
||||||
|
0,
|
||||||
|
) as u32;
|
||||||
|
let rows = std::cmp::max(
|
||||||
|
bufinfo.srWindow.Bottom as i32 - bufinfo.srWindow.Top as i32 + 1,
|
||||||
|
0,
|
||||||
|
) as u32;
|
||||||
|
|
||||||
|
Ok(ConsoleSize { cols, rows })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue