Skip to content

Commit

Permalink
starlark: fix uint32->int truncation on 386 (google#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
adonovan authored Feb 23, 2021
1 parent 0147c08 commit e043a3d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions starlark/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func hash(thread *Thread, _ *Builtin, args Tuple, kwargs []Tuple) (Value, error)
return nil, err
}

var h int
var h int64
switch x := x.(type) {
case String:
// The Starlark spec requires that the hash function be
Expand All @@ -488,13 +488,13 @@ func hash(thread *Thread, _ *Builtin, args Tuple, kwargs []Tuple) (Value, error)
// String.Hash, which uses the fastest implementation
// available, because as varies across process restarts,
// and may evolve with the implementation.
h = int(javaStringHash(string(x)))
h = int64(javaStringHash(string(x)))
case Bytes:
h = int(softHashString(string(x))) // FNV32
h = int64(softHashString(string(x))) // FNV32
default:
return nil, fmt.Errorf("hash: got %s, want string or bytes", x.Type())
}
return MakeInt(h), nil
return MakeInt64(h), nil
}

// javaStringHash returns the same hash as would be produced by
Expand Down

0 comments on commit e043a3d

Please sign in to comment.