...
Non-Compliant Code Example
In this example derived from Dowd, an automatic variable is used to modify the environment via a call to putenv(). When that environment variable is retrieved using getenv(), it may have a value that is different than the value supplied to putenv(). Note that this example also violates rule DCL30-C. Do not refer to an object outside of its lifetime.
| Code Block | ||
|---|---|---|
| ||
int func(char *editor) { char env[10]; strcpy(env,"VAR=1"); putenv(env); return 0; } int main (int argc, char * argv[]) { char *var; func(); /* ... */ var = getenv("VAR"); return 0; } |
Compliant Solution
...