Skip to content

Commit

Permalink
do not rely on undefined behaviour in bytes_test.go
Browse files Browse the repository at this point in the history
8 exbi equals 2^64, therefore it cannot be stored in int64. The tests use
the fact that on x86_64 the following expressions holds true:
int64(0) - 1 == math.MaxInt64.

However, this is not true for other platforms, specifically aarch64, s390x
and ppc64le.

This commit fixes it by testing the library with 7 exbi.

Fixes labstack#37
  • Loading branch information
ondrejbudai committed Aug 26, 2020
1 parent 4919956 commit 2337700
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions bytes/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,22 @@ func TestBytesParse(t *testing.T) {
}

// EB
b, err = Parse("8EB")
b, err = Parse("7EB")
if assert.NoError(t, err) {
assert.True(t, math.MaxInt64 == b-1)
assert.Equal(t, 7*int64(1152921504606846976), b)
}
b, err = Parse("8E")
b, err = Parse("7E")
if assert.NoError(t, err) {
assert.True(t, math.MaxInt64 == b-1)
assert.Equal(t, 7*int64(1152921504606846976), b)
}

// EB with spaces
b, err = Parse("8 EB")
b, err = Parse("7 EB")
if assert.NoError(t, err) {
assert.True(t, math.MaxInt64 == b-1)
assert.Equal(t, 7*int64(1152921504606846976), b)
}
b, err = Parse("8 E")
b, err = Parse("7 E")
if assert.NoError(t, err) {
assert.True(t, math.MaxInt64 == b-1)
assert.Equal(t, 7*int64(1152921504606846976), b)
}
}

0 comments on commit 2337700

Please sign in to comment.