ffi_gen icon indicating copy to clipboard operation
ffi_gen copied to clipboard

flexible arrays (char x[]) incorrectly translate as :pointer

Open ghazel opened this issue 10 years ago • 0 comments

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.

ghazel avatar Apr 02 '15 03:04 ghazel