https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83859
Bug ID: 83859 Summary: Please add new attribute which will establish relation between parameters for buffer and its size Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: bugzi...@poradnik-webmastera.com Target Milestone: --- gcc can detect if buffer size passed to function like strncpy is incorrect, e.g. it is sizeof pointer. It would be good to have similar diagnostics enabled for custom functions also accepts buffer and its size. Please add new function attribute which would allow to do this and appropriate diagnostics which will use it. I propose to add following attribute with two parameters - indices of buffer and its size arguments. Note that function may accept multiple such pairs, so it should be possible to use this attribute multiple times. __attribute__((buffer_size(1, 2))) void foo(char* dst, size_t dstsize);