Skip to content

Commit

Permalink
Fix int overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cpuguy83 committed Jun 17, 2021
1 parent 8db1f69 commit 7879a6d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions winterm/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,28 @@ func ensureInRange(n int16, min int16, max int16) int16 {

func GetStdFile(nFile int) (*os.File, uintptr) {
var file *os.File
switch nFile {
case syscall.STD_INPUT_HANDLE, windows.STD_INPUT_HANDLE:

// syscall uses negative numbers
// windows package uses very big uint32
// Keep these switches split so we don't have to convert ints too much.
switch uint32(nFile) {
case windows.STD_INPUT_HANDLE:
file = os.Stdin
case syscall.STD_OUTPUT_HANDLE, windows.STD_OUTPUT_HANDLE:
case windows.STD_OUTPUT_HANDLE:
file = os.Stdout
case syscall.STD_ERROR_HANDLE, windows.STD_ERROR_HANDLE:
case windows.STD_ERROR_HANDLE:
file = os.Stderr
default:
panic(fmt.Errorf("Invalid standard handle identifier: %v", nFile))
switch nFile {
case syscall.STD_INPUT_HANDLE:
file = os.Stdin
case syscall.STD_OUTPUT_HANDLE:
file = os.Stdout
case syscall.STD_ERROR_HANDLE:
file = os.Stderr
default:
panic(fmt.Errorf("Invalid standard handle identifier: %v", nFile))
}
}

fd, err := syscall.GetStdHandle(nFile)
Expand Down

0 comments on commit 7879a6d

Please sign in to comment.