https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67793

            Bug ID: 67793
           Summary: Detect incorrect function arg sizes at compile time.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rusty at rustcorp dot com.au
  Target Milestone: ---

It would be great if GCC warned on this:

extern int func_(char x[32]);
int main(int argc, char *argv[])
{
        char p[8];

        return func(p);
}

Failing that, if __builtin_object_size() returned a compile-time constant where
possible, we could do this (with __builtin_constant_p):

#define SIZE_CHECK(v,min) ({static_assert(__builtin_object_size((v), 0) >=
(min), "too small"); (v)})

extern int func_(char x[32]);
#define func(x) func_(SIZE_CHECK((x),32))

Reply via email to