Re: ffi initializer bit me today

  • From: Cosmin Apreutesei <cosmin.apreutesei@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sat, 8 Sep 2012 23:02:04 +0300

> In your first case, did you mean to say 'abc' ? For copying 3 bytes?

See, that's why I think it can lead to subtle bugs: it copies 'ab\0'.
It's even harder to spot when you see code like this:

local cdata = ffi.new('unsigned char[?]', #s, s)

which instead should be:

local cdata = ffi.new('unsigned char[?]', #s+1, s)

The behavior is documented, just IMHO a bit inconsistent.

Other related posts: