Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make amino build on 32bit architectures #242

Merged
merged 4 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.14.1 (November 6, 2018)

IMPROVEMENTS:
- go-amino compiles again on 32-bit platforms ([#242])

[#242]: https://github.com/tendermint/go-amino/pull/242

## 0.14.0 (October 26, 2018)

BREAKING CHANGE:
Expand Down
11 changes: 5 additions & 6 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func EncodeFloat64(w io.Writer, f float64) (err error) {

const (
// seconds of 01-01-0001
minSeconds = -62135596800
minSeconds int64 = -62135596800
// seconds of 10000-01-01
maxSeconds = 253402300800
maxSeconds int64 = 253402300800

// nanos have to be in interval: [0, 999999999]
maxNanos = 999999999
Expand All @@ -137,9 +137,7 @@ func (e InvalidTimeErr) Error() string {
// Milliseconds are used to ease compatibility with Javascript,
// which does not support finer resolution.
func EncodeTime(w io.Writer, t time.Time) (err error) {
var s = t.Unix()
var ns = int32(t.Nanosecond()) // this int64 -> int32 is safe.

s := t.Unix()
// TODO: We are hand-encoding a struct until MarshalAmino/UnmarshalAmino is supported.
// skip if default/zero value:
if s != 0 {
Expand All @@ -156,9 +154,10 @@ func EncodeTime(w io.Writer, t time.Time) (err error) {
return
}
}
ns := int32(t.Nanosecond()) // this int64 -> int32 cast is safe (nanos are in [0, 999999999])
// skip if default/zero value:
if ns != 0 {
// do not encode if not in interval [0, 999999999]
// do not encode if nanos exceed allowed interval
if ns < 0 || ns > maxNanos {
// we could as well panic here:
// time.Time.Nanosecond() guarantees nanos to be in [0, 999,999,999]
Expand Down
5 changes: 3 additions & 2 deletions tests/fuzz/binary/init-corpus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log"
"math"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -48,7 +49,7 @@ func main() {
Int32Ar: [4]int32{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, 0x77777777},
Int64Ar: [4]int64{0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x80808000FFFFF},
VarintAr: [4]int64{0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x80808000FFFFF},
IntAr: [4]int{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, 0x80808000},
IntAr: [4]int{0x7FFFFFFF, 0x6FFFFFFF, 0x5FFFFFFF, math.MaxInt32},
ByteAr: [4]byte{0xDE, 0xAD, 0xBE, 0xEF},
Uint8Ar: [4]uint8{0xFF, 0xFF, 0x00, 0x88},
Uint16Ar: [4]uint16{0xFFFF, 0xFFFF, 0xFF00, 0x8800},
Expand All @@ -66,7 +67,7 @@ func main() {
Int32Sl: []int32{0x6FFFFFFF, 0x5FFFFFFF, 0x7FFFFFFF, 0x7F000000},
Int64Sl: []int64{0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0x80808000FFFFF},
VarintSl: []int64{0x5FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x80808000FFFFF},
IntSl: []int{0x6FFFFFFF, 0x7FFFFFFF, 0x80808000, 0x5FFFFFFF},
IntSl: []int{0x6FFFFFFF, 0x7FFFFFFF, math.MaxInt32, 0x5FFFFFFF},
ByteSl: []byte{0xAD, 0xBE, 0xDE, 0xEF},
Uint8Sl: []uint8{0xFF, 0x00, 0x88, 0xFF},
Uint16Sl: []uint16{0xFFFF, 0xFFFF, 0xFF00, 0x8800},
Expand Down