diff --git a/samples/bugreport/eclectic.fbs b/samples/bugreport/eclectic.fbs index ad507e712..f01e9f3a0 100644 --- a/samples/bugreport/eclectic.fbs +++ b/samples/bugreport/eclectic.fbs @@ -1,11 +1,17 @@ namespace Eclectic; +table Buffer { + data:[uint8]; +} + enum Fruit : byte { Banana = -1, Orange = 42 } table FooBar { meal : Fruit = Banana; density : long (deprecated); say : string; height : short; + + buffers:[Buffer]; } file_identifier "NOOB"; root_type FooBar; diff --git a/samples/bugreport/myissue.c b/samples/bugreport/myissue.c index 00982355a..36242779f 100644 --- a/samples/bugreport/myissue.c +++ b/samples/bugreport/myissue.c @@ -2,6 +2,8 @@ #include "build/myissue_generated.h" #include "flatcc/support/hexdump.h" +#include + int main(int argc, char *argv[]) { int ret; @@ -15,16 +17,38 @@ int main(int argc, char *argv[]) B = &builder; flatcc_builder_init(B); + #define BUFFER_COUNT 5 + const int sizes[BUFFER_COUNT] = { + 1, + 16, + 22, + 55, + 123, + }; + Eclectic_Buffer_ref_t buffer_refs[BUFFER_COUNT]; + for (int i = 0; i < BUFFER_COUNT; ++i) { + Eclectic_Buffer_start(B); + flatcc_builder_start_vector(B, 1, /*align=*/16, FLATBUFFERS_COUNT_MAX(1)); + uint8_t* p = flatcc_builder_extend_vector(B, sizes[i]); + memset(p, 'x', sizes[i]); + flatcc_builder_ref_t data = flatcc_builder_end_vector(B); + Eclectic_Buffer_data_add(B, data); + buffer_refs[i] = Eclectic_Buffer_end(B); + } + flatcc_builder_ref_t buffers_vec = flatcc_builder_create_offset_vector(B, buffer_refs, BUFFER_COUNT); + Eclectic_FooBar_start_as_root(B); Eclectic_FooBar_say_create_str(B, "hello"); Eclectic_FooBar_meal_add(B, Eclectic_Fruit_Orange); Eclectic_FooBar_height_add(B, -8000); + Eclectic_FooBar_buffers_add(B, buffers_vec); Eclectic_FooBar_end_as_root(B); buf = flatcc_builder_get_direct_buffer(B, &size); -#if defined(PROVOKE_ERROR) || 0 - /* Provoke error for testing. */ - ((char*)buf)[0] = 42; -#endif + + FILE* f = fopen("output.bin", "wb"); + fwrite(buf,1, size, f); + fclose(f); + ret = Eclectic_FooBar_verify_as_root(buf, size); if (ret) { hexdump("Eclectic.FooBar buffer for myissue", buf, size, stdout);