...
This is a compliant code solution. If it is necessary to modify the value of the string returned by the function getenv()
, then the programmer should make a local copy of that string value, and then modify the local copy of that string.
Code Block | ||
---|---|---|
| ||
const char *env;
char *copy_of_env;
if ((env = getenv("TEST_ENV")) != NULL) {
copy_of_env = malloc(strlen(env) + 1);
if (copy_of_env != NULL) {
strcpy(copy_of_env, env);
}
else {
/* Error handling */
}
copy_of_env[0] = 'a';
}
|
...