Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Protect against negative argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ocheron committed Feb 24, 2020
1 parent 2e0a60f commit 981b97a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Crypto/Internal/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Data.Memory.PtrMethods (memSet)
import Foreign.Ptr (Ptr, plusPtr)
import Foreign.Storable (poke)

import Crypto.Internal.Imports
import Crypto.Internal.Imports hiding (empty)

data Builder = Builder !Int (Ptr Word8 -> IO ()) -- size and initializer

Expand All @@ -47,4 +47,7 @@ bytes :: ByteArrayAccess ba => ba -> Builder
bytes bs = Builder (B.length bs) (B.copyByteArrayToPtr bs)

zero :: Int -> Builder
zero s = Builder s (\p -> memSet p 0 s)
zero s = if s > 0 then Builder s (\p -> memSet p 0 s) else empty

empty :: Builder
empty = Builder 0 (const $ return ())

0 comments on commit 981b97a

Please sign in to comment.