Skip to content

Commit

Permalink
Jpg: Use B.unsafeIndex where we already bounds-checked
Browse files Browse the repository at this point in the history
  • Loading branch information
nh2 committed Dec 7, 2022
1 parent f88c124 commit 76d8cbc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Codec/Picture/Jpg/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import qualified Data.Vector.Storable.Mutable as M
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Unsafe as BU

import Data.Int( Int16 )
import Data.Word(Word8, Word16 )
Expand Down Expand Up @@ -618,7 +619,7 @@ parseECS = do
loop !v !offset_in_chunk
| offset_in_chunk >= B.length chunk = Left (v, chunk)
| otherwise =
let !vNext = B.index chunk offset_in_chunk
let !vNext = BU.unsafeIndex chunk offset_in_chunk -- bounds check is done above
!isReset = 0xD0 <= vNext && vNext <= 0xD7
!vIsSegmentMarker = v == 0xFF && vNext /= 0 && not isReset
in
Expand Down

0 comments on commit 76d8cbc

Please sign in to comment.