1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* * Rule: MEM35-C * Source: wiki * Status: PASS - Should NOT trigger MEM35-C violation */ #include <stdint.h> #include <stdlib.h> void function(size_t len) { long *p; if (len == 0 || len > SIZE_MAX / sizeof(*p)) { /* Handle overflow */ } p = (long *)malloc(len * sizeof(*p)); if (p == NULL) { /* Handle error */ } free(p); }