• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kshard / wreck / 11204017987

06 Oct 2024 06:01PM UTC coverage: 53.106% (-0.3%) from 53.438%
11204017987

Pull #3

github

fogfish
update ci/cd
Pull Request #3: (fix): check read buffer size

1 of 4 new or added lines in 1 file covered. (25.0%)

171 of 322 relevant lines covered (53.11%)

0.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.6
/codec.go
1
//
2
// Copyright (C) 2024 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license. See the LICENSE file for details.
6
// https://github.com/kshard/wreck
7
//
8

9
package wreck
10

11
import (
12
        "encoding/binary"
13
        "errors"
14
        "io"
15
)
16

17
type Chunk struct {
18
        UniqueKey []uint8
19
        SortKey   []uint8
20
        Vector    []uint8
21
}
22

23
func Encode(w io.Writer, wreck *Chunk) error {
1✔
24
        var head [8]uint8
1✔
25

1✔
26
        szData := len(wreck.Vector)
1✔
27
        szUniqueKey := len(wreck.UniqueKey)
1✔
28
        szSortKey := len(wreck.SortKey)
1✔
29
        szWreck := szData + szUniqueKey + szSortKey
1✔
30

1✔
31
        binary.LittleEndian.PutUint32(head[0:4], uint32(szWreck))
1✔
32
        binary.LittleEndian.PutUint16(head[4:6], uint16(szData))
1✔
33
        binary.LittleEndian.PutUint16(head[6:8], uint16(szSortKey))
1✔
34

1✔
35
        if _, err := w.Write(head[:]); err != nil {
1✔
36
                return err
×
37
        }
×
38

39
        if szData > 0 {
2✔
40
                if _, err := w.Write(wreck.Vector); err != nil {
1✔
41
                        return err
×
42
                }
×
43
        }
44

45
        if szSortKey > 0 {
2✔
46
                if _, err := w.Write(wreck.SortKey); err != nil {
1✔
47
                        return err
×
48
                }
×
49
        }
50

51
        if szUniqueKey > 0 {
2✔
52
                if _, err := w.Write(wreck.UniqueKey); err != nil {
1✔
53
                        return err
×
54
                }
×
55
        }
56

57
        return nil
1✔
58
}
59

60
func Decode(r io.Reader, wreck *Chunk) error {
1✔
61
        var head [8]uint8
1✔
62

1✔
63
        if _, err := io.ReadFull(r, head[:]); err != nil {
1✔
64
                return err
×
65
        }
×
66

67
        szWreck := int(binary.LittleEndian.Uint32(head[0:4]))
1✔
68
        szData := int(binary.LittleEndian.Uint16(head[4:6]))
1✔
69
        szSortKey := int(binary.LittleEndian.Uint16(head[6:8]))
1✔
70
        szUniqueKey := szWreck - szData - szSortKey
1✔
71

1✔
72
        b := make([]uint8, szWreck)
1✔
73
        if n, err := io.ReadFull(r, b); err != nil {
1✔
74
                if !errors.Is(err, io.EOF) {
×
75
                        return err
×
76
                }
×
77

NEW
78
                if n != szWreck {
×
NEW
79
                        return io.ErrUnexpectedEOF
×
NEW
80
                }
×
81
        }
82

83
        if szData == 0 {
2✔
84
                wreck.Vector = nil
1✔
85
        } else {
2✔
86
                wreck.Vector = b[0:szData]
1✔
87
        }
1✔
88

89
        if szSortKey == 0 {
2✔
90
                wreck.SortKey = nil
1✔
91
        } else {
2✔
92
                wreck.SortKey = b[szData : szData+szSortKey]
1✔
93
        }
1✔
94

95
        if szUniqueKey == 0 {
2✔
96
                wreck.UniqueKey = nil
1✔
97
        } else {
2✔
98
                wreck.UniqueKey = b[szData+szSortKey : szData+szSortKey+szUniqueKey]
1✔
99
        }
1✔
100

101
        return nil
1✔
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc