...
| Code Block |
|---|
size_t str_size = calc_size(other_string); char *str_copy = malloc(str_size); strncpyif (str_copy == NULL) { /* handle error */ } strcpy(str_copy, other_string, str_size); |
Compliant Code Example 1
...
| Code Block |
|---|
size_t str_size = calc_size(other_string);
if (str_size != 0) {
char *str_copy = malloc(str_size);
if (str_copy == NULL) {
/* handle error */
check return value}
strncpystrcpy(str_copy, other_string, str_size);
}
|