class Foo < FFI::Struct
layout :length, :int,
:data, :pointer
end
However, this is incorrect. Data is not a pointer in the sense that memcpy(&f->data, bad, sizeof(void*)) would populate bad with the pointer value. It would instead copy the first sizeof(void*) bytes of the array. Thus, ffi gets a pointer with the first few bytes of the array as the value, which is invalid to dereference.
Translates as:
However, this is incorrect. Data is not a pointer in the sense that
memcpy(&f->data, bad, sizeof(void*))
would populatebad
with the pointer value. It would instead copy the firstsizeof(void*)
bytes of the array. Thus, ffi gets a pointer with the first few bytes of the array as the value, which is invalid to dereference.