From 660309f9069fb48580073e9866f8853c3af74a43 Mon Sep 17 00:00:00 2001 From: Maxence Maireaux Date: Tue, 15 Oct 2024 10:22:26 +0200 Subject: [PATCH] Fix code scanning alert no. 1: Incorrect conversion between integer types Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- testing/platform/pgtesting/postgres.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/testing/platform/pgtesting/postgres.go b/testing/platform/pgtesting/postgres.go index 5cee0c1..dfc07bd 100644 --- a/testing/platform/pgtesting/postgres.go +++ b/testing/platform/pgtesting/postgres.go @@ -18,6 +18,7 @@ import ( _ "github.com/lib/pq" "github.com/pkg/errors" "github.com/stretchr/testify/require" + "math" ) type T interface { @@ -63,10 +64,13 @@ type PostgresServer struct { } func (s *PostgresServer) GetPort() int { - v, err := strconv.ParseInt(s.Port, 10, 64) + v, err := strconv.ParseInt(s.Port, 10, 32) if err != nil { panic(err) } + if v < math.MinInt32 || v > math.MaxInt32 { + panic(fmt.Sprintf("Port value out of range: %d", v)) + } return int(v) }