From: Thomas Hurst Date: 2007-05-06T01:04:18+09:00 Subject: Re: Problem with memcpy, marshal, zero * Daniel Berger (djberg96@gmail.com) wrote: > h = {"gvalue"=>0} > m = Marshal.dump(h) > p m => "\004\b{\006\"\vgvaluei\000" > memcpy(address, marshal, marshal.length) > > The problem is that trailing "\000" gets chopped off by the memcpy > function because it treats it like a trailing null as far as I can > tell. So, when I try to load it again the marshal data isn't > identical, i.e. the trailing "\000" is gone, and I end up getting a > "marshal data too short" error. > > What's the solution here? At the end of Win32API_Call() I see: case _T_POINTER: return rb_str_new2((char *)ret); rb_str_new2 does rb_str_new(ptr, strlen(ptr)), so if you're using Win32API to return any string with a NULL byte, it'll get truncated. On the other hand, I've not spotted anything wrt input to suggest NULL is handled as a delimiter; are you sure the NULL isn't being copied properly, but not being returned properly by another call? -- Thomas 'Freaky' Hurst http://hur.st/