Versions Compared

Key

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

...

If the string returned by getenv() must be altered, a local copy should be created. Altering the string returned by getenv() is undefined behavior. (see See undefined behavior 184.).

Similarly, subclause 7.11.1.1, paragraph 8 [ISO/IEC 9899:2011], defines setlocale() as follows:

...

Altering the string returned by setlocale() or the structure returned by localeconv() are undefined behaviors. (see See undefined behaviors 120 and 121.) . Furthermore, the C Standard imposes no requirements on the contents of the string by setlocale(). Consequently, no assumptions can be made as to the string's internal contents or structure.

Finally, subclause 7.24.6.2, paragraph 4 [ISO/IEC 9899:2011], states:

The strerror function returns a pointer to the string, the contents of which are locale-specific. The array pointed to shall not be modified by the program, but may be overwritten by a subsequent call to the strerror function.

Altering the string returned by strerror() is undefined behavior. (see See undefined behavior 184.).

Noncompliant Code Example (getenv())

...