Skip to content

Commit bb8a73a

Browse files
all: run go fix (#818)
1 parent ec8db0d commit bb8a73a

3 files changed

Lines changed: 6 additions & 19 deletions

File tree

‎internal/cdf/cdf.go‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,7 @@ func (c *cdf) readLong(sid int32, length uint32) []byte {
383383
if off64 >= int64(len(c.data)) {
384384
return nil
385385
}
386-
end64 := off64 + int64(n)*int64(c.secSize)
387-
if end64 > int64(len(c.data)) {
388-
end64 = int64(len(c.data))
389-
}
386+
end64 := min(off64+int64(n)*int64(c.secSize), int64(len(c.data)))
390387
out := c.data[off64:end64]
391388
if length > 0 && int(length) < len(out) {
392389
out = out[:length]
@@ -464,10 +461,7 @@ func (c *cdf) dirLen() int { return len(c.dirRaw) / dirEntrySize }
464461
// stopping at the first NUL.
465462
func (c *cdf) dirAt(i int, out *dirEntry) {
466463
raw := c.dirRaw[i*dirEntrySize:]
467-
nameLen := int(binary.LittleEndian.Uint16(raw[64:]))
468-
if nameLen > 64 {
469-
nameLen = 64
470-
}
464+
nameLen := min(int(binary.LittleEndian.Uint16(raw[64:])), 64)
471465
k := uint8(0)
472466
for j := 0; j < nameLen/2; j++ {
473467
// Names are ASCII; keep the low byte of each little-endian UTF-16

‎internal/magic/geo.go‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package magic
33
import (
44
"bytes"
55
"encoding/binary"
6+
"slices"
67
)
78

89
// Shp matches a shape format file.
@@ -39,13 +40,7 @@ func Shp(raw []byte, limit uint32) bool {
3940
31, // MultiPatch
4041
}
4142

42-
for _, st := range shapeTypes {
43-
if st == int(binary.LittleEndian.Uint32(raw[108:112])) {
44-
return true
45-
}
46-
}
47-
48-
return false
43+
return slices.Contains(shapeTypes, int(binary.LittleEndian.Uint32(raw[108:112])))
4944
}
5045

5146
// Shx matches a shape index format file.

‎internal/magic/video.go‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ func isMatroskaFileTypeMatched(in []byte, flType string) bool {
4949
// The logic of search is: find first instance of \x42\x82 and then
5050
// search for given string after n bytes of above instance.
5151
func isFileTypeNamePresent(in []byte, flType string) bool {
52-
ind, maxInd, lenIn := 0, 4096, len(in)
53-
if lenIn < maxInd { // restricting length to 4096
54-
maxInd = lenIn
55-
}
52+
ind, lenIn := 0, len(in)
53+
maxInd := min(4096, lenIn)
5654
ind = bytes.Index(in[:maxInd], []byte("\x42\x82"))
5755
if ind > 0 && lenIn > ind+2 {
5856
ind += 2

0 commit comments

Comments
 (0)