Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED

  • From: Geoff Leyland <geoff_leyland@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 22 Jun 2012 09:58:09 +1200

On 22/06/2012, at 9:12 AM, Adam Strzelecki wrote:

> But indeed I agree there's something wrong with ffi.new which allows to 
> "allocate" zero sized array. Shouldn't it raise an error ffi.new("char[?]", 
> 0, ...) ?


C doesn't complain about a zero-sized malloc:

echo "void* malloc(unsigned long); main() { malloc(0); }" | gcc -x c -o test - 
; ./test

The FFI semantics page has a section titled "No Hand-holding" 
(http://luajit.org/ext_ffi_semantics.html)


Other related posts: