lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 08.11.2011 14:35, Mike Pall wrote:

No, it's really two steps in one, like malloc() + memcpy(). If you
don't want to create the space for the extra \0, simply use:

  local l = #str
  local s = ffi.new("char[?]", l)
  ffi.copy(s, str, l)
  -- Don't use ffi.copy(s, str), since that would copy the \0, too.

But what I find the most strange is that the segfault doesn't happen
at that line, it happens later when the memory is garbage collected.

The extra byte written beyond the end of the array trashes the
memory allocator info.

OK, that explains it, thanks.