https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116983
qinzhao at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |qinzhao at gcc dot gnu.org --- Comment #1 from qinzhao at gcc dot gnu.org --- (In reply to Kees Cook from comment #0) > When counted_by is present in a structure, it means that the object must be > a singleton. > > For example: > > struct counted { > int counter; > int array[] __attribute__((counted_by(counter))); > }; > > struct notcounted { > int counter; > int array[]; > }; > > void __attribute__((noinline)) emit_length(size_t length) > { > printf("%zu\n", length); > } > > // This correctly cannot know size of p object, and returns SIZE_MAX > void objsize_notcounted(struct notcounted *p) > { > emit_length(__builtin_dynamic_object_size(p, 1)); > } > > // This must be operating on a singleton, therefor the > // return must be: > // max(sizeof(*p), > // sizeof(*p) + offsetof(typeof(*p), array) * p->counter) > void objsize_counted(struct counted *p) > { > emit_length(__builtin_dynamic_object_size(p, 1)); > } could you explicitly explain what's wrong in the current implementation?