Skip to content

Commit

Permalink
Merge pull request #124 from nats-io/fix_int_overflows
Browse files Browse the repository at this point in the history
Fix int overflows on i386
  • Loading branch information
kozlovic authored Jul 7, 2016
2 parents 31562b2 + c1e060c commit af51f85
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nats-streaming-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func parseFlags() (*stand.Options, *natsd.Options) {
flag.Int64Var(&stanOpts.FileStoreOpts.CompactMinFileSize, "file_compact_min_size", stores.DefaultFileStoreOptions.CompactMinFileSize, "Minimum file size for compaction")
flag.IntVar(&stanOpts.FileStoreOpts.BufferSize, "file_buffer_size", stores.DefaultFileStoreOptions.BufferSize, "File buffer size (in bytes)")
flag.BoolVar(&stanOpts.FileStoreOpts.DoCRC, "file_crc", stores.DefaultFileStoreOptions.DoCRC, "Enable file CRC-32 checksum")
flag.IntVar(&stanOpts.FileStoreOpts.CRCPolynomial, "file_crc_poly", stores.DefaultFileStoreOptions.CRCPolynomial, "Polynomial used to make the table used for CRC-32 checksum")
flag.Int64Var(&stanOpts.FileStoreOpts.CRCPolynomial, "file_crc_poly", stores.DefaultFileStoreOptions.CRCPolynomial, "Polynomial used to make the table used for CRC-32 checksum")
flag.IntVar(&stanOpts.IOBatchSize, "io_batch_size", stand.DefaultIOBatchSize, "# of message to batch in flushing io")
flag.Int64Var(&stanOpts.IOSleepTime, "io_sleep_time", stand.DefaultIOSleepTime, "duration the server waits for more messages (in micro-seconds, 0 to disable)")
// NATS options
Expand Down
8 changes: 4 additions & 4 deletions stores/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type FileStoreOptions struct {
DoCRC bool

// CRCPoly is a polynomial used to make the table used in CRC computation.
CRCPolynomial int
CRCPolynomial int64
}

// DefaultFileStoreOptions defines the default options for a File Store.
Expand All @@ -85,7 +85,7 @@ var DefaultFileStoreOptions = FileStoreOptions{
CompactFragmentation: 50,
CompactMinFileSize: 1024 * 1024,
DoCRC: true,
CRCPolynomial: crc32.IEEE,
CRCPolynomial: int64(crc32.IEEE),
}

// BufferSize is a FileStore option that sets the size of the buffer used
Expand Down Expand Up @@ -148,7 +148,7 @@ func DoCRC(enableCRC bool) FileStoreOption {
// CRCPolynomial is a FileStore option that defines the polynomial to use to create
// the table used for CRC-32 Checksum.
// See https://golang.org/pkg/hash/crc32/#MakeTable
func CRCPolynomial(polynomial int) FileStoreOption {
func CRCPolynomial(polynomial int64) FileStoreOption {
return func(o *FileStoreOptions) error {
o.CRCPolynomial = polynomial
return nil
Expand Down Expand Up @@ -412,7 +412,7 @@ func NewFileStore(rootDir string, limits *ChannelLimits, options ...FileStoreOpt
// Convert the compact interval in time.Duration
fs.compactItvl = time.Duration(fs.opts.CompactInterval) * time.Second
// Create the table using polynomial in options
if fs.opts.CRCPolynomial == crc32.IEEE {
if fs.opts.CRCPolynomial == int64(crc32.IEEE) {
fs.crcTable = crc32.IEEETable
} else {
fs.crcTable = crc32.MakeTable(uint32(fs.opts.CRCPolynomial))
Expand Down
4 changes: 2 additions & 2 deletions stores/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestFSOptions(t *testing.T) {
CompactInterval: 60,
CompactMinFileSize: 1024 * 1024,
DoCRC: false,
CRCPolynomial: crc32.Castagnoli,
CRCPolynomial: int64(crc32.Castagnoli),
}
// Create the file with custom options
fs, _, err := NewFileStore(defaultDataStore, &testDefaultChannelLimits,
Expand All @@ -232,7 +232,7 @@ func TestFSOptions(t *testing.T) {
CompactInterval(expected.CompactInterval),
CompactMinFileSize(expected.CompactMinFileSize),
DoCRC(expected.DoCRC),
CRCPolynomial(int(expected.CRCPolynomial)))
CRCPolynomial(expected.CRCPolynomial))
if err != nil {
t.Fatalf("Unexpected error on file store create: %v", err)
}
Expand Down

0 comments on commit af51f85

Please sign in to comment.