1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* * Rule: STR32-C * Source: wiki * Status: FAIL - Should trigger STR32-C violation */ #include <string.h> enum { STR_SIZE = 32 }; size_t func(const char *source) { char c_str[STR_SIZE]; size_t ret = 0; if (source) { c_str[sizeof(c_str) - 1] = '\0'; strncpy(c_str, source, sizeof(c_str)); ret = strlen(c_str); } else { /* Handle null pointer */ } return ret; }