From f8bac7c0e83ae48c17ff474266ec845e3ae0e3e4 Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Sat, 30 Apr 2022 16:11:36 +0100 Subject: [PATCH] Fix nlreturn lint warnings --- internal/aes7z/reader.go | 3 +++ internal/bcj2/reader.go | 3 +++ internal/bzip2/reader.go | 2 ++ internal/deflate/reader.go | 2 ++ internal/delta/reader.go | 1 + internal/lzma/reader.go | 2 ++ internal/lzma2/reader.go | 2 ++ internal/util/reader.go | 2 ++ reader.go | 12 ++++++++++++ register.go | 1 + struct.go | 10 ++++++++++ 11 files changed, 40 insertions(+) diff --git a/internal/aes7z/reader.go b/internal/aes7z/reader.go index 0fd9f07..64ce314 100644 --- a/internal/aes7z/reader.go +++ b/internal/aes7z/reader.go @@ -24,6 +24,7 @@ func (rc *readCloser) Close() error { err = rc.rc.Close() rc.rc, rc.br = nil, nil } + return err } @@ -33,6 +34,7 @@ func (rc *readCloser) Password(p string) error { return err } rc.br = cipherio.NewBlockReader(rc.rc, cipher.NewCBCDecrypter(block, rc.iv)) + return nil } @@ -43,6 +45,7 @@ func (rc *readCloser) Read(p []byte) (int, error) { if rc.br == nil { return 0, errors.New("aes7z: no password set") } + return rc.br.Read(p) } diff --git a/internal/bcj2/reader.go b/internal/bcj2/reader.go index 9112eba..3094476 100644 --- a/internal/bcj2/reader.go +++ b/internal/bcj2/reader.go @@ -90,6 +90,7 @@ func (rc *readCloser) Close() error { if rc.main != nil { err = multierror.Append(err, rc.main.Close(), rc.call.Close(), rc.jump.Close(), rc.rd.Close()) } + return err.ErrorOrNil() } @@ -127,6 +128,7 @@ func (rc *readCloser) decode(i int) (bool, error) { if err := rc.update(); err != nil { return false, err } + return false, nil } @@ -136,6 +138,7 @@ func (rc *readCloser) decode(i int) (bool, error) { if err := rc.update(); err != nil { return false, err } + return true, nil } diff --git a/internal/bzip2/reader.go b/internal/bzip2/reader.go index 968b220..3b809df 100644 --- a/internal/bzip2/reader.go +++ b/internal/bzip2/reader.go @@ -17,6 +17,7 @@ func (rc *readCloser) Close() error { err = rc.c.Close() rc.c, rc.r = nil, nil } + return err } @@ -24,6 +25,7 @@ func (rc *readCloser) Read(p []byte) (int, error) { if rc.r == nil { return 0, errors.New("bzip2: Read after Close") } + return rc.r.Read(p) } diff --git a/internal/deflate/reader.go b/internal/deflate/reader.go index c694a8e..5673f05 100644 --- a/internal/deflate/reader.go +++ b/internal/deflate/reader.go @@ -27,6 +27,7 @@ func (rc *readCloser) Close() error { err = rc.c.Close() rc.c, rc.fr = nil, nil } + return err } @@ -36,6 +37,7 @@ func (rc *readCloser) Read(p []byte) (int, error) { if rc.fr == nil { return 0, errors.New("deflate: Read after Close") } + return rc.fr.Read(p) } diff --git a/internal/delta/reader.go b/internal/delta/reader.go index 7c332a5..31e501d 100644 --- a/internal/delta/reader.go +++ b/internal/delta/reader.go @@ -20,6 +20,7 @@ func (rc *readCloser) Close() (err error) { err = rc.rc.Close() rc.rc = nil } + return } diff --git a/internal/lzma/reader.go b/internal/lzma/reader.go index d9ce5a2..2086846 100644 --- a/internal/lzma/reader.go +++ b/internal/lzma/reader.go @@ -20,6 +20,7 @@ func (rc *readCloser) Close() error { err = rc.c.Close() rc.c, rc.r = nil, nil } + return err } @@ -27,6 +28,7 @@ func (rc *readCloser) Read(p []byte) (int, error) { if rc.r == nil { return 0, errors.New("lzma: Read after Close") } + return rc.r.Read(p) } diff --git a/internal/lzma2/reader.go b/internal/lzma2/reader.go index 6b04bdc..0c4677e 100644 --- a/internal/lzma2/reader.go +++ b/internal/lzma2/reader.go @@ -18,6 +18,7 @@ func (rc *readCloser) Close() error { err = rc.c.Close() rc.c, rc.r = nil, nil } + return err } @@ -25,6 +26,7 @@ func (rc *readCloser) Read(p []byte) (int, error) { if rc.r == nil { return 0, errors.New("lzma2: Read after Close") } + return rc.r.Read(p) } diff --git a/internal/util/reader.go b/internal/util/reader.go index 2362d46..31ed9f5 100644 --- a/internal/util/reader.go +++ b/internal/util/reader.go @@ -41,6 +41,7 @@ func (rc *byteReadCloser) ReadByte() (byte, error) { if n == 0 { return 0, io.ErrNoProgress } + return b[0], nil } @@ -50,5 +51,6 @@ func ByteReadCloser(r io.ReadCloser) ReadCloser { if rc, ok := r.(ReadCloser); ok { return rc } + return &byteReadCloser{r} } diff --git a/reader.go b/reader.go index df57ca4..2ea3318 100644 --- a/reader.go +++ b/reader.go @@ -92,6 +92,7 @@ func OpenReaderWithPassword(name, password string) (*ReadCloser, error) { info, err := f.Stat() if err != nil { err = multierror.Append(err, f.Close()) + return nil, err } @@ -110,6 +111,7 @@ func OpenReaderWithPassword(name, password string) (*ReadCloser, error) { for _, file := range files { err = multierror.Append(err, file.Close()) } + return nil, err } files = append(files, f) @@ -119,6 +121,7 @@ func OpenReaderWithPassword(name, password string) (*ReadCloser, error) { for _, file := range files { err = multierror.Append(err, file.Close()) } + return nil, err } @@ -134,6 +137,7 @@ func OpenReaderWithPassword(name, password string) (*ReadCloser, error) { for _, file := range files { err = multierror.Append(err, file.Close()) } + return nil, err } r.f = files @@ -245,6 +249,7 @@ func readSizes(r io.ByteReader, count uint64) ([]uint64, error) { } sizes[i] = size } + return sizes, nil } @@ -327,6 +332,7 @@ func readCoder(r util.Reader) (*coder, error) { if err != nil { return nil, err } + return nil, errIncompleteRead } @@ -355,6 +361,7 @@ func readCoder(r util.Reader) (*coder, error) { if err != nil { return nil, err } + return nil, errIncompleteRead } } @@ -427,6 +434,7 @@ func readUnpackInfo(r util.Reader) (*unpackInfo, error) { if err != nil { return nil, err } + return nil, errUnexpectedID } @@ -463,6 +471,7 @@ func readUnpackInfo(r util.Reader) (*unpackInfo, error) { if err != nil { return nil, err } + return nil, errUnexpectedID } @@ -706,6 +715,7 @@ func readNames(r util.Reader, count, length uint64) ([]string, error) { if i != count { return nil, errors.New("sevenzip: wrong number of filenames") } + return names, nil } @@ -1019,6 +1029,7 @@ func (z *Reader) init(r io.ReaderAt, size int64) error { if err != nil { return err } + return errUnexpectedID } @@ -1074,5 +1085,6 @@ func (rc *ReadCloser) Close() error { for _, f := range rc.f { err = multierror.Append(err, f.Close()) } + return err.ErrorOrNil() } diff --git a/register.go b/register.go index 05146d2..2dc9a9c 100644 --- a/register.go +++ b/register.go @@ -62,5 +62,6 @@ func decompressor(method []byte) Decompressor { if !ok { return nil } + return di.(Decompressor) } diff --git a/struct.go b/struct.go index dc4ee43..6fdb14c 100644 --- a/struct.go +++ b/struct.go @@ -98,6 +98,7 @@ func (f *folder) findInBindPair(i uint64) *bindPair { return v } } + return nil } @@ -107,6 +108,7 @@ func (f *folder) findOutBindPair(i uint64) *bindPair { return v } } + return nil } @@ -150,6 +152,7 @@ func newFolderReadCloser(rc io.ReadCloser) io.ReadCloser { nrc := new(folderReadCloser) nrc.h = crc32.NewIEEE() nrc.rc = plumbing.TeeReadCloser(rc, nrc.h) + return nrc } @@ -162,6 +165,7 @@ func (f *folder) unpackSize() uint64 { return f.size[i] } } + return f.size[len(f.size)-1] } @@ -202,6 +206,7 @@ func (si *streamsInfo) FileFolderAndSize(file int) (int, uint64) { if streams == 1 { return folder, si.unpackInfo.folder[folder].size[len(si.unpackInfo.folder[folder].coder)-1] } + return folder, si.subStreamsInfo.size[file] } @@ -213,6 +218,7 @@ func (si *streamsInfo) folderOffset(folder int) int64 { } k += si.unpackInfo.folder[i].packedStreams } + return int64(si.packInfo.position + offset) } @@ -278,6 +284,7 @@ func (si *streamsInfo) FolderReader(r io.ReaderAt, folder int, password string) if si.unpackInfo.digest != nil { return fr, si.unpackInfo.digest[folder], nil } + return fr, 0, nil } @@ -363,6 +370,7 @@ func (h *FileHeader) Mode() (mode os.FileMode) { } else { mode = msdosModeToFileMode(h.Attributes) } + return } @@ -375,6 +383,7 @@ func msdosModeToFileMode(m uint32) (mode os.FileMode) { if m&msdosReadOnly != 0 { mode &^= 0222 } + return mode } @@ -405,5 +414,6 @@ func unixModeToFileMode(m uint32) os.FileMode { if m&sISVTX != 0 { mode |= os.ModeSticky } + return mode }