[Haskell-cafe] Re: user error when using Text.Regex.PCRE

Don Stewart dons at galois.com
Tue Nov 20 14:10:23 EST 2007


haskell:
> Thank you very much for the error report.  I have tracked down the cause.
> 
> You are searching against an empty Bytestring.  This is now represented by
> 
> > -- | /O(1)/ The empty 'ByteString'
> > empty :: ByteString
> > empty = PS nullForeignPtr 0 0
> 
> And while the useAsCString and useAsCStringLen functions never reveal the null
> pointer, the current library uses unsafeUseAsCStringLen, which returns the null
> pointer.
> 
> And this is getting caught by a null pointer check resulting in your crash.  I
> will post a fix later tonight, and announce it.

Right, empty bytestrings are represented as a nullPtr and a 0 length
field.  When you use unsafeUseAs* operations, this pointer is passed to
a C function as is, without copying.

The side condition is that the C function should accept NULL as a
0-length string, which the pcre code evidently doesn't, so its unsafe to
use unsafeUseAsCStringLen here,

I'll add some more explanatory text about the side conditions that need
to hold for this use to be safe, and advise not using unsafe things :)

-- Don


More information about the Haskell-Cafe mailing list