ffi_gen
ffi_gen copied to clipboard
flexible arrays (char x[]) incorrectly translate as :pointer
struct foo {
int length;
char data[];
}
Translates as:
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.