Skip to content

Commit d2b61e0

Browse files
authored
Started the iterating over Data at the startIndex.
Data uses slices which may not start at 0. When a Data is supplied which does not start at 0, the first index previously used would throw a bad access exception. This happened for example with a Data value returns from CBOR previously. It does not per-se start with a slice at 0.
1 parent aa0be91 commit d2b61e0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/CBORCoding/CBORParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ internal class CBORParser {
2020
guard !data.isEmpty else { return nil }
2121

2222
var storage = Storage()
23-
var index: Int = 0
23+
var index: Int = data.startIndex
2424

2525
do {
26-
while index < data.count {
26+
while index < data.endIndex {
2727
let majorType = CBOR.majorType(for: data[index])
2828

2929
switch majorType {

0 commit comments

Comments
 (0)