Skip to content

System.Win32.Types.failWith segfaults on unknown error code

If a (Windows) system call returns an error code not known to FormatMessage, System.Win32.Types.failWith segfaults. failWith incorrectly assumes that getErrorMessage never returns a NULL pointer.

A simple fix in failWith is to replace:

  msg <- peekTString c_msg
  -- We ignore failure of freeing c_msg, given we're already failing
  _ <- localFree c_msg

by:

  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
Edited by Simon Marlow
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information