[Haskell-cafe] Need help with very simple C++ FFI call

Brandon Allbery allbery.b at gmail.com
Tue Nov 19 16:19:42 UTC 2013

On Tue, Nov 19, 2013 at 11:06 AM, Yuras Shumovich <shumovichy at gmail.com>wrote:

> IIRC, strlen doesn't count the terminating '\0', so you'll need to
> malloc(strlen(*ascii) + 1).
> Not sure why python works, maybe just different memory layout hides the
> bug.

Also note that different memory allocators have different behaviors;
depending on block size rounding, string length and arena accounting
overhead, the allocated block may be larger than requested. So the malloc()
that Python provides may possibly be returning something "accidentally"
large enough to handle the NUL anyway. (I don't know if Python actually
overrides/replaces the default malloc(); some other interpreters do.)

brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131119/86584e76/attachment.html>

More information about the Haskell-Cafe mailing list