Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This non-compliant code example showing that modification of the string value returned by the function getenv().

Code Block
bgColor#FFcccc
int foo()
{
    char *env;
    env = getenv("TEST_ENV");
    env[0] = 'a';

    /*Do some more things*/

    return 0;
}

...

Code Block
bgColor#ccccFF
int foo()
{
    char *env;
    char *copy_of_env;

    env = getenv("TEST_ENV");
    copy_of_env = malloc( strlen(env) * sizeof(char)+ 1 );
    /* Error handling */
    strcpy(copy_of_env, env);

    copy_of_env[0] = 'a';

    /*Do some more things*/

    return 0;
}

...