Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

failWith: allow GetErrorMessage to return NULL (#3815)

  • Loading branch information...
commit bb0911571e5aae1486dcbf6069f0a8a6f3f0cd0b 1 parent 07a004a
@simonmar simonmar authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 System/Win32/Types.hs
View
11 System/Win32/Types.hs
@@ -23,6 +23,7 @@ import Foreign.C
import Control.Exception
import System.IO.Error
import Data.Char
+import Numeric (showHex)
----------------------------------------------------------------
-- Platform specific definitions
@@ -204,9 +205,12 @@ errorWin fn_name = do
failWith :: String -> ErrCode -> IO a
failWith fn_name err_code = do
c_msg <- getErrorMessage err_code
- msg <- peekTString c_msg
- -- We ignore failure of freeing c_msg, given we're already failing
- _ <- localFree c_msg
+ msg <- if c_msg == nullPtr
+ then return $ "Error 0x" ++ Numeric.showHex err_code ""
+ else do msg <- peekTString c_msg
+ -- We ignore failure of freeing c_msg, given we're already failing
+ _ <- localFree c_msg
+ return msg
c_maperrno -- turn GetLastError() into errno, which errnoToIOError knows
-- how to convert to an IOException we can throw.
-- XXX we should really do this directly.
@@ -216,6 +220,7 @@ failWith fn_name err_code = do
`ioeSetErrorString` msg'
throw ioerror
+
foreign import ccall unsafe "maperrno" -- in base/cbits/Win32Utils.c
c_maperrno :: IO ()
Please sign in to comment.
Something went wrong with that request. Please try again.