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

            Bug ID: 77531
           Summary: __attribute__((alloc_size(1,2))) could also warn on
                    multiplication overflow
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crrodriguez at opensuse dot org
  Target Milestone: ---

Using the example in the docs:

void* my_calloc(size_t x , size_t y) __attribute__((alloc_size(1,2)))

since alloc_size(1,2) means the function will return memory of  x *y..when the
compiler knows that multiplying x * y will cause an integer overflow..let's say
a obvious case my_calloc(SIZE_MAX, SIZE_MAX); it could either warn, error or
trap before an integer overflow actually happens.. (using the same logic as
__builtin_mul_overflow() I guess)

Reply via email to