Skip to content

Commit 62fda2c

Browse files
committed
Fix bug in withFilePath
1 parent 29a6131 commit 62fda2c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

System/Posix/ByteString/FilePath.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ decodeWithBasePosix ba = B.useAsCStringLen ba $ \fp -> peekFilePathPosix fp
153153
-- | Wrapper around 'useAsCString', checking the encoded 'FilePath' for internal NUL octets as these are
154154
-- disallowed in POSIX filepaths. See https://gitlab.haskell.org/ghc/ghc/-/issues/13660
155155
useAsCStringSafe :: RawFilePath -> (CString -> IO a) -> IO a
156-
useAsCStringSafe path f = useAsCStringLen path $ \(ptr, len) -> do
156+
useAsCStringSafe path f = useAsCString path $ \ptr -> do
157+
let len = B.length path
157158
clen <- c_strlen ptr
158159
if clen == fromIntegral len
159160
then f ptr

System/Posix/PosixPath/FilePath.hsc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import Data.ByteString.Internal (c_strlen)
4545
import Control.Monad
4646
import Control.Exception
4747
import System.OsPath.Posix as PS
48-
import System.OsPath.Data.ByteString.Short
48+
import System.OsPath.Data.ByteString.Short as BSS
4949
import Prelude hiding (FilePath)
5050
import System.OsString.Internal.Types (PosixString(..), pattern PS)
5151
import GHC.IO.Exception
@@ -147,7 +147,8 @@ _toStr = fmap PS.toChar . PS.unpack
147147
-- | Wrapper around 'useAsCString', checking the encoded 'FilePath' for internal NUL octets as these are
148148
-- disallowed in POSIX filepaths. See https://gitlab.haskell.org/ghc/ghc/-/issues/13660
149149
useAsCStringSafe :: PosixPath -> (CString -> IO a) -> IO a
150-
useAsCStringSafe pp@(PS path) f = useAsCStringLen path $ \(ptr, len) -> do
150+
useAsCStringSafe pp@(PS path) f = useAsCString path $ \ptr -> do
151+
let len = BSS.length path
151152
clen <- c_strlen ptr
152153
if clen == fromIntegral len
153154
then f ptr

0 commit comments

Comments
 (0)