Skip to content

Commit

Permalink
optimized overflow logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerdsilva committed Mar 19, 2024
1 parent 08131bd commit 2d14c7e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Sources/HummingbirdCore/Utils/HBParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,9 @@ extension Parser {
func _percentDecode(_ original: ArraySlice<UInt8>, _ bytes: UnsafeMutableBufferPointer<UInt8>) throws -> Int {
var newIndex = 0
var index = original.startIndex

while index < original.endIndex {
while index < (original.endIndex - 2) {
// if we have found a percent sign
if original[index] == 0x25 {
guard original.endIndex - index >= 2 else {
throw DecodeError()
}
let high = Self.asciiHexValues[Int(original[index + 1])]
let low = Self.asciiHexValues[Int(original[index + 2])]
index += 3
Expand All @@ -617,9 +613,13 @@ extension Parser {
index += 1
}
}
while index < original.endIndex {
bytes[newIndex] = original[index]
newIndex += 1
index += 1
}
return newIndex
}

guard self.index != self.range.endIndex else { return "" }
do {
if #available(macOS 11, macCatalyst 14.0, iOS 14.0, tvOS 14.0, *) {
Expand Down

0 comments on commit 2d14c7e

Please sign in to comment.