diff --git a/s2/cmd/s2c/main.go b/s2/cmd/s2c/main.go index 4292d62783..9e913562ac 100644 --- a/s2/cmd/s2c/main.go +++ b/s2/cmd/s2c/main.go @@ -91,7 +91,7 @@ Options:`) flag.PrintDefaults() os.Exit(0) } - opts := []s2.WriterOption{s2.WriterBlockSize(int(sz)), s2.WriterConcurrency(*cpu), s2.WriterPadding(int(pad))} + opts := []s2.WriterOption{s2.WriterBlockSize(sz), s2.WriterConcurrency(*cpu), s2.WriterPadding(pad)} if *index { opts = append(opts, s2.WriterAddIndex()) } @@ -123,7 +123,7 @@ Options:`) dstFile, err := os.OpenFile(*out, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm) exitErr(err) defer dstFile.Close() - bw := bufio.NewWriterSize(dstFile, int(sz)*2) + bw := bufio.NewWriterSize(dstFile, sz*2) defer bw.Flush() wr.Reset(bw) } @@ -612,7 +612,7 @@ func exitErr(err error) { } // toSize converts a size indication to bytes. -func toSize(size string) (uint64, error) { +func toSize(size string) (int, error) { size = strings.ToUpper(strings.TrimSpace(size)) firstLetter := strings.IndexFunc(size, unicode.IsLetter) if firstLetter == -1 { @@ -620,18 +620,18 @@ func toSize(size string) (uint64, error) { } bytesString, multiple := size[:firstLetter], size[firstLetter:] - bytes, err := strconv.ParseUint(bytesString, 10, 64) + sz, err := strconv.Atoi(bytesString) if err != nil { return 0, fmt.Errorf("unable to parse size: %v", err) } switch multiple { case "M", "MB", "MIB": - return bytes * 1 << 20, nil + return sz * 1 << 20, nil case "K", "KB", "KIB": - return bytes * 1 << 10, nil + return sz * 1 << 10, nil case "B", "": - return bytes, nil + return sz, nil default: return 0, fmt.Errorf("unknown size suffix: %v", multiple) } diff --git a/s2/cmd/s2d/main.go b/s2/cmd/s2d/main.go index 5fc0abe692..8f7030183d 100644 --- a/s2/cmd/s2d/main.go +++ b/s2/cmd/s2d/main.go @@ -292,9 +292,9 @@ Options:`) rs, err := r.ReadSeeker(tailBytes > 0, nil) exitErr(err) if tailBytes > 0 { - _, err = rs.Seek(-int64(tailBytes), io.SeekEnd) + _, err = rs.Seek(-tailBytes, io.SeekEnd) } else { - _, err = rs.Seek(int64(offset), io.SeekStart) + _, err = rs.Seek(offset, io.SeekStart) } exitErr(err) } @@ -408,7 +408,7 @@ func (w *rCountSeeker) BytesRead() int64 { } // toSize converts a size indication to bytes. -func toSize(size string) (uint64, error) { +func toSize(size string) (int64, error) { if len(size) == 0 { return 0, nil } @@ -419,22 +419,25 @@ func toSize(size string) (uint64, error) { } bytesString, multiple := size[:firstLetter], size[firstLetter:] - bytes, err := strconv.ParseUint(bytesString, 10, 64) + sz, err := strconv.ParseInt(bytesString, 10, 64) if err != nil { return 0, fmt.Errorf("unable to parse size: %v", err) } + if sz < 0 { + return 0, errors.New("negative size given") + } switch multiple { case "T", "TB", "TIB": - return bytes * 1 << 40, nil + return sz * 1 << 40, nil case "G", "GB", "GIB": - return bytes * 1 << 30, nil + return sz * 1 << 30, nil case "M", "MB", "MIB": - return bytes * 1 << 20, nil + return sz * 1 << 20, nil case "K", "KB", "KIB": - return bytes * 1 << 10, nil + return sz * 1 << 10, nil case "B", "": - return bytes, nil + return sz, nil default: return 0, fmt.Errorf("unknown size suffix: %v", multiple) }