diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-05-11 22:14:26 +0100 |
---|---|---|
committer | Paulo Gomes <pjbgf@linux.com> | 2023-05-11 22:14:26 +0100 |
commit | bddd89e697ebdaad2fe341b3e8a3233691f5544a (patch) | |
tree | 9226bdd5f898f0813126e6df5f99ddf2bfec08c5 /plumbing/format/idxfile/writer.go | |
parent | cb72b58b7576e28627e58338c92e61d3d41a72d7 (diff) | |
download | go-git-bddd89e697ebdaad2fe341b3e8a3233691f5544a.tar.gz |
*: Add missing error checks
Some areas of the code base were missing error checks,
without them it may be harder to troubleshoot unexpected
behaviours.
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'plumbing/format/idxfile/writer.go')
-rw-r--r-- | plumbing/format/idxfile/writer.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/plumbing/format/idxfile/writer.go b/plumbing/format/idxfile/writer.go index e556013..c4c21e1 100644 --- a/plumbing/format/idxfile/writer.go +++ b/plumbing/format/idxfile/writer.go @@ -136,15 +136,23 @@ func (w *Writer) createIndex() (*MemoryIndex, error) { offset := o.Offset if offset > math.MaxInt32 { - offset = w.addOffset64(offset) + var err error + offset, err = w.addOffset64(offset) + if err != nil { + return nil, err + } } buf.Truncate(0) - binary.WriteUint32(buf, uint32(offset)) + if err := binary.WriteUint32(buf, uint32(offset)); err != nil { + return nil, err + } idx.Offset32[bucket] = append(idx.Offset32[bucket], buf.Bytes()...) buf.Truncate(0) - binary.WriteUint32(buf, o.CRC32) + if err := binary.WriteUint32(buf, o.CRC32); err != nil { + return nil, err + } idx.CRC32[bucket] = append(idx.CRC32[bucket], buf.Bytes()...) } @@ -158,15 +166,17 @@ func (w *Writer) createIndex() (*MemoryIndex, error) { return idx, nil } -func (w *Writer) addOffset64(pos uint64) uint64 { +func (w *Writer) addOffset64(pos uint64) (uint64, error) { buf := new(bytes.Buffer) - binary.WriteUint64(buf, pos) - w.index.Offset64 = append(w.index.Offset64, buf.Bytes()...) + if err := binary.WriteUint64(buf, pos); err != nil { + return 0, err + } + w.index.Offset64 = append(w.index.Offset64, buf.Bytes()...) index := uint64(w.offset64 | (1 << 31)) w.offset64++ - return index + return index, nil } func (o objects) Len() int { |