Re: patch applied (packages/Win32): malloc a big enough buffer for the registry functions. Fixes trac #2097.
Ross Paterson <ross <at> soi.city.ac.uk>
2008-04-07 07:48:05 GMT
On Sun, Apr 06, 2008 at 10:08:41PM +0100, Neil Mitchell wrote:
> > We were mallocing a byte per tchar, but tchars are normally 2 bytes big...
> > I think they are at most 4 bytes, so we now malloc 4 * #tchars. Not sure
> > if there is a proper function I should be using for this?
>
> TCHAR is #ifdef'd to be either CHAR on Win 9x/ME (1 byte), or WCHAR on
> Win 2k/XP/Vista (2 bytes). In C you'd just do sizeof(TCHAR), not sure
> if there is a way of doing this from Haskell.
Well there's sizeof (undefined :: TCHAR). Where the pointer has type
LPTSTR = Ptr TCHAR, mallocArray will do it. (Actually allocaArray seems
like a better choice in this context.)