Skip to content

Commit

Permalink
Fix overflows of untyped int constants on 32-bit
Browse files Browse the repository at this point in the history
9223372036 as an untyped int constant will overflow on 32-bit archs.

math.MaxInt64 is an untyped int constant (1<<63 - 1), and will thus also
overflow on 32-bit if not cast to an int64.

Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
  • Loading branch information
dswarbrick committed Aug 12, 2024
1 parent 1dade5b commit 008d7b8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions helpers/templates/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestHumanizeTimestamp(t *testing.T) {
{name: "negative", input: -1, expected: "1969-12-31 23:59:59 +0000 UTC"},
{name: "one", input: 1, expected: "1970-01-01 00:00:01 +0000 UTC"},
{name: "past", input: 1234567, expected: "1970-01-15 06:56:07 +0000 UTC"},
{name: "future", input: 9223372036, expected: "2262-04-11 23:47:16 +0000 UTC"},
{name: "future", input: int64(9223372036), expected: "2262-04-11 23:47:16 +0000 UTC"},
// Uint
{name: "zero", input: uint64(0), expected: "1970-01-01 00:00:00 +0000 UTC"},
{name: "one", input: uint64(1), expected: "1970-01-01 00:00:01 +0000 UTC"},
Expand Down Expand Up @@ -118,6 +118,6 @@ func TestHumanizeTimestamp(t *testing.T) {
}

func TestHumanizeTimestampError(t *testing.T) {
_, err := HumanizeTimestamp(math.MaxInt64)
_, err := HumanizeTimestamp(int64(math.MaxInt64))
require.Error(t, err)
}

0 comments on commit 008d7b8

Please sign in to comment.