Skip to content

Commit

Permalink
Merge pull request #162 from abema/update-for-code-analysis
Browse files Browse the repository at this point in the history
Update for code analysis
  • Loading branch information
sunfish-shogi authored Jan 17, 2024
2 parents 15ec6e6 + ba46040 commit 81d0a24
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 22 deletions.
3 changes: 1 addition & 2 deletions box_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mp4
import (
"bytes"
"io"
"io/ioutil"
"testing"

"github.com/orcaman/writerseeker"
Expand Down Expand Up @@ -108,7 +107,7 @@ func TestWriteBoxInfo(t *testing.T) {
if !c.hasError {
require.NoError(t, err)
assert.Equal(t, c.expectedBI, bi)
b, err := ioutil.ReadAll(w.Reader())
b, err := io.ReadAll(w.Reader())
require.NoError(t, err)
assert.Equal(t, c.expectedBytes, b)
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/mp4tool/internal/dump/dump_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dump

import (
"io/ioutil"
"io"
"os"
"testing"

Expand Down Expand Up @@ -51,7 +51,7 @@ func TestDump(t *testing.T) {
os.Stdout = w
Main(append(tc.options, tc.file))
w.Close()
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
require.NoError(t, err)
assert.Equal(t, tc.wants, string(b))
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/mp4tool/internal/extract/extract_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package extract

import (
"io/ioutil"
"io"
"os"
"testing"

Expand Down Expand Up @@ -46,7 +46,7 @@ func TestExtract(t *testing.T) {
os.Stdout = w
require.Zero(t, Main([]string{tc.boxType, tc.file}))
w.Close()
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
require.NoError(t, err)
assert.Equal(t, tc.expectedSize, len(b))
assert.Equal(t, tc.boxType, string(b[4:8]))
Expand Down
4 changes: 2 additions & 2 deletions cmd/mp4tool/internal/probe/probe_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package probe

import (
"io/ioutil"
"io"
"os"
"testing"

Expand Down Expand Up @@ -44,7 +44,7 @@ func TestProbe(t *testing.T) {
os.Stdout = w
Main(append(tc.options, tc.file))
w.Close()
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
require.NoError(t, err)
assert.Equal(t, tc.wants, string(b))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/mp4tool/internal/psshdump/psshdump_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package psshdump

import (
"io/ioutil"
"io"
"os"
"testing"

Expand Down Expand Up @@ -54,7 +54,7 @@ func TestPsshdump(t *testing.T) {
os.Stdout = w
Main(append(tc.options, tc.file))
w.Close()
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
require.NoError(t, err)
assert.Equal(t, tc.wants, string(b))
})
Expand Down
7 changes: 7 additions & 0 deletions field.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mp4

import (
"fmt"
"math"
"os"
"reflect"
"sort"
Expand Down Expand Up @@ -179,6 +180,9 @@ func buildField(fieldName string, tag string) *field {
if err != nil {
panic(err)
}
if ver > math.MaxUint8 {
panic("ver-tag must be <=255")
}
f.version = uint8(ver)
}

Expand All @@ -188,6 +192,9 @@ func buildField(fieldName string, tag string) *field {
if err != nil {
panic(err)
}
if ver > math.MaxUint8 {
panic("nver-tag must be <=255")
}
f.nVersion = uint8(ver)
}

Expand Down
12 changes: 3 additions & 9 deletions marshaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ func readerHasSize(reader bitio.ReadSeeker, size uint64) bool {
}

_, err = reader.Seek(pre, io.SeekStart)
if err != nil {
return false
}

return true
return err == nil
}

type marshaller struct {
Expand Down Expand Up @@ -128,8 +124,7 @@ func (m *marshaller) marshalStruct(v reflect.Value, fs []*field) error {
func (m *marshaller) marshalArray(v reflect.Value, fi *fieldInstance) error {
size := v.Type().Size()
for i := 0; i < int(size)/int(v.Type().Elem().Size()); i++ {
var err error
err = m.marshal(v.Index(i), fi)
err := m.marshal(v.Index(i), fi)
if err != nil {
return err
}
Expand Down Expand Up @@ -414,8 +409,7 @@ func (u *unmarshaller) unmarshalStruct(v reflect.Value, fs []*field) error {
func (u *unmarshaller) unmarshalArray(v reflect.Value, fi *fieldInstance) error {
size := v.Type().Size()
for i := 0; i < int(size)/int(v.Type().Elem().Size()); i++ {
var err error
err = u.unmarshal(v.Index(i), fi)
err := u.unmarshal(v.Index(i), fi)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion read.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func readBoxStructure(r io.ReadSeeker, totalSize uint64, isRoot bool, path BoxPa
}

if totalSize != 0 && !ctx.IsQuickTimeCompatible {
return nil, errors.New("Unexpected EOF")
return nil, errors.New("unexpected EOF")
}

return vals, nil
Expand Down
3 changes: 1 addition & 2 deletions write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mp4
import (
"bytes"
"io"
"io/ioutil"
"testing"

"gopkg.in/src-d/go-billy.v4/memfs"
Expand Down Expand Up @@ -110,7 +109,7 @@ func TestWriter(t *testing.T) {

_, err = output.Seek(0, io.SeekStart)
require.NoError(t, err)
bin, err := ioutil.ReadAll(output)
bin, err := io.ReadAll(output)
require.NoError(t, err)
assert.Equal(t, []byte{
// ftyp
Expand Down

0 comments on commit 81d0a24

Please sign in to comment.