diff --git a/cli/azd/pkg/input/console.go b/cli/azd/pkg/input/console.go index d87770b8ab7..f32108243df 100644 --- a/cli/azd/pkg/input/console.go +++ b/cli/azd/pkg/input/console.go @@ -925,13 +925,22 @@ func (c *AskerConsole) Handles() ConsoleHandles { } // consoleWidth the number of columns in the active console window -func consoleWidth() int { - width, _ := consolesize.GetConsoleSize() - return width +func consoleWidth() int32 { + widthInt, _ := consolesize.GetConsoleSize() + + // Suppress G115: integer overflow conversion int -> int32 below. + // Explanation: + // consolesize.GetConsoleSize() returns an int, but the underlying implementation actually is a uint16 on both + // Windows and unix systems. + // + // In practice, console width is the number of columns (text) in the active console window. + // We don't ever expect this to be larger than math.MaxInt32, so we can safely cast to int32. + // nolint:gosec // G115 + return int32(widthInt) } -func (c *AskerConsole) handleResize(width int) { - c.consoleWidth.Store(int32(width)) +func (c *AskerConsole) handleResize(width int32) { + c.consoleWidth.Store(width) c.spinnerLineMu.Lock() if c.spinner.Status() == yacspin.SpinnerRunning { @@ -1045,7 +1054,7 @@ func NewConsole( c.spinner, _ = yacspin.New(spinnerConfig) c.spinnerTerminalMode = spinnerConfig.TerminalMode if isTerminal { - c.consoleWidth = atomic.NewInt32(int32(consoleWidth())) + c.consoleWidth = atomic.NewInt32(consoleWidth()) watchTerminalResize(c) watchTerminalInterrupt(c) } diff --git a/cli/azd/pkg/ioc/container.go b/cli/azd/pkg/ioc/container.go index ec8ae9021dc..24670bd6c39 100644 --- a/cli/azd/pkg/ioc/container.go +++ b/cli/azd/pkg/ioc/container.go @@ -9,7 +9,6 @@ import ( "fmt" "reflect" "regexp" - "unsafe" "github.com/golobby/container/v3" ) @@ -90,11 +89,11 @@ func NewRegistrationsOnly(from *NestedContainer) *NestedContainer { } func getUnexportedField(field reflect.Value) interface{} { - return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface() + return reflect.NewAt(field.Type(), field.Addr().UnsafePointer()).Elem().Interface() } func setUnexportedField(field reflect.Value, value interface{}) { - reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())). + reflect.NewAt(field.Type(), field.Addr().UnsafePointer()). Elem(). Set(reflect.ValueOf(value)) } diff --git a/cli/azd/pkg/output/ux/list_as_text.go b/cli/azd/pkg/output/ux/list_as_text.go index d33a6d70b88..268aaff08f5 100644 --- a/cli/azd/pkg/output/ux/list_as_text.go +++ b/cli/azd/pkg/output/ux/list_as_text.go @@ -17,7 +17,7 @@ import ( func ListAsText(items []string) string { count := len(items) if count < 1 { - log.Panic("calling itemsCountAsText() with empty list.") + log.Panic("calling ListAsText() with empty list.") } if count == 1 { @@ -25,6 +25,7 @@ func ListAsText(items []string) string { } if count == 2 { + //nolint:gosec // G602: slice index out of range - false positive, we know the slice has at least 2 elements return fmt.Sprintf("%s and %s", items[0], items[1]) } diff --git a/cli/azd/pkg/tools/github/github.go b/cli/azd/pkg/tools/github/github.go index f8b1c2ce95d..d56a8904e50 100644 --- a/cli/azd/pkg/tools/github/github.go +++ b/cli/azd/pkg/tools/github/github.go @@ -517,7 +517,7 @@ func extractFromTar(src, dst string) (string, error) { // cspell: disable-next-line `Typeflag` is comming fron *tar.Header if fileHeader.Typeflag == tar.TypeReg && fileName == "gh" { filePath := filepath.Join(dst, fileName) - ghCliFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(fileHeader.Mode)) + ghCliFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fileHeader.FileInfo().Mode()) if err != nil { return extractedAt, err } diff --git a/cli/azd/pkg/tools/pack/pack.go b/cli/azd/pkg/tools/pack/pack.go index 0b4c93e5dc1..d027d19d52f 100644 --- a/cli/azd/pkg/tools/pack/pack.go +++ b/cli/azd/pkg/tools/pack/pack.go @@ -322,7 +322,7 @@ func extractFromTar( // cspell: disable-next-line `Typeflag` is comming fron *tar.Header if fileHeader.Typeflag == tar.TypeReg && fileName == "pack" { filePath := filepath.Join(out, fileName) - packCliFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(fileHeader.Mode)) + packCliFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fileHeader.FileInfo().Mode()) if err != nil { return extractedAt, err }