Skip to content

Commit

Permalink
Fix bug in withFilePath
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Sep 16, 2023
1 parent 29a6131 commit a69ae80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion System/Posix/ByteString/FilePath.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ decodeWithBasePosix ba = B.useAsCStringLen ba $ \fp -> peekFilePathPosix fp
-- | Wrapper around 'useAsCString', checking the encoded 'FilePath' for internal NUL octets as these are
-- disallowed in POSIX filepaths. See https://gitlab.haskell.org/ghc/ghc/-/issues/13660
useAsCStringSafe :: RawFilePath -> (CString -> IO a) -> IO a
useAsCStringSafe path f = useAsCStringLen path $ \(ptr, len) -> do
useAsCStringSafe path f = useAsCString path $ \ptr -> do
let len = B.length path
clen <- c_strlen ptr
if clen == fromIntegral len
then f ptr
Expand Down
5 changes: 3 additions & 2 deletions System/Posix/PosixPath/FilePath.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import Data.ByteString.Internal (c_strlen)
import Control.Monad
import Control.Exception
import System.OsPath.Posix as PS
import System.OsPath.Data.ByteString.Short
import System.OsPath.Data.ByteString.Short as BSS
import Prelude hiding (FilePath)
import System.OsString.Internal.Types (PosixString(..), pattern PS)
import GHC.IO.Exception
Expand Down Expand Up @@ -147,7 +147,8 @@ _toStr = fmap PS.toChar . PS.unpack
-- | Wrapper around 'useAsCString', checking the encoded 'FilePath' for internal NUL octets as these are
-- disallowed in POSIX filepaths. See https://gitlab.haskell.org/ghc/ghc/-/issues/13660
useAsCStringSafe :: PosixPath -> (CString -> IO a) -> IO a
useAsCStringSafe pp@(PS path) f = useAsCStringLen path $ \(ptr, len) -> do
useAsCStringSafe pp@(PS path) f = useAsCString path $ \ptr -> do
let len = BSS.length path
clen <- c_strlen ptr
if clen == fromIntegral len
then f ptr
Expand Down

0 comments on commit a69ae80

Please sign in to comment.