TestDecodeOverflows fails on m1 macs
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 108
Description
fails here:
```golang
func TestDecodeOverflows(tt *testing.T) {
t := func(p interface{}, n float64, ts string) {
assertDecodeErrorMessage(tt, types.Float(n), p, fmt.Sprintf("Cannot unmarshal from: Float to: %s details: (%g does not fit in %s)", ts, n, ts))
}
var ui8 uint8
t(&ui8, 256, "uint8")
t(&ui8, -1, "uint8") <-----------
```
Passes on m1 mac, but fails on others:
```
func Test2(t *testing.T) {
v := float64(-1)
require.Equal(t, uint64(0), uint64(v))
}
```
In uintDecoder we cast a negative float to uint64. The result `u`, contains a value 0 on m1 macs which passes the overflow check:
```golang
func uintDecoder(ctx context.Context, nbf *types.NomsBinFormat, v types.Value, rv reflect.Value) error {
if n, ok := v.(types.Float); ok {
u := uint64(n) <-----------------------
if rv.OverflowUint(u) {
return overflowError(nbf, n, rv.Type())
}
rv.SetUint(u)
return nil
}
// types.Uint is currently encoded as types.Float during marshalling
// the block below exists to prepare for a compatibility breaking change
// todo: update comment after breaking change is made
if n, ok := v.(types.Uint); ok {
rv.SetUint(uint64(n))
return nil
}
return &UnmarshalTypeMismatchError{v, rv.Type(), "", nbf}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.