[GHC] #9395: Debug.Trace should not use %s for format string

GHC ghc-devs at haskell.org
Sat Aug 2 19:57:56 UTC 2014


#9395: Debug.Trace should not use %s for format string
-------------------------------------+-------------------------------------
       Reporter:  ezyang             |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  libraries/base     |                 Version:  7.8.2
       Keywords:                     |        Operating System:
   Architecture:  Unknown/Multiple   |  Unknown/Multiple
     Difficulty:  Unknown            |         Type of failure:  Incorrect
     Blocked By:                     |  result at runtime
Related Tickets:                     |               Test Case:
                                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 The current implementation of traceIO in Debug.Trace is as follows:

 {{{
 traceIO :: String -> IO ()
 traceIO msg = do
     withCString "%s\n" $ \cfmt ->
      withCString msg  $ \cmsg ->
       debugBelch cfmt cmsg
 }}}

 This is bad news: it means if the String has a null in it, the string will
 be silently truncated.  For example, in GHC, this means that you cannot
 pretty-print FastString uniques, since the default printing algorithm
 often results in a null.

 Probably the proper thing to do here is to also pass a length indicator
 for the CString. We should also fix unique pretty-printing to never
 generate nulls. A good test case would be:

 {{{
 main = trace "\0foo" (return ())
 }}}

 which should have non-empty output.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9395>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list