From 981b97a132a4110aeb5a15f986b1bdf3631c274b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Ch=C3=A9ron?= Date: Sun, 23 Feb 2020 09:06:00 +0100 Subject: [PATCH] Protect against negative argument --- Crypto/Internal/Builder.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Crypto/Internal/Builder.hs b/Crypto/Internal/Builder.hs index fd5b9208..bc072e3d 100644 --- a/Crypto/Internal/Builder.hs +++ b/Crypto/Internal/Builder.hs @@ -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 @@ -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 ())