...
Code Block | ||||
---|---|---|---|---|
| ||||
#define __STDC_WANT_LIB_EXT1__ 1 #include <string.h> enum { STR_SIZE = 32 }; size_t func(const char *source) { char a[STR_SIZE]; size_t ret = 0; if (source) { errno_t err = strncpy_s( a, sizeof(a), source, strlenstrnlen(source, sizeof(a)) ); if (err != 0) { /* Handle error */ } else { ret = strnlen_s(a, sizeof(a)); } } else { /* Handle null pointer */ } return ret; } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string.h> enum { STR_SIZE = 32 }; size_t func(const char *source) { char c_str[STR_SIZE]; size_t ret = 0; if (source) { if (strlenstrnlen(source, sizeof(c_str)) < sizeof(c_str)) { strcpy(c_str, source); ret = strlen(c_str); } else { /* Handle string-too-large */ } } else { /* Handle null pointer */ } return ret; } |
...