Some functions return a pointer to an object that cannot be modified without causing undefined behavior. These functions include the standard getenv()
, setlocale()
, localeconv()
, and strerror()
functions.
...
Consequently, if the string returned by getenv()
must be altered, a local copy should be created. Altering the string returned by getenv()
results in undefined behavior. See also undefined behavior 174 of Annex J of C99.
Wiki Markup |
---|
Similarly, C99 \[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] defines {{setlocale}} and {{localeconv}} as follows: |
...
Altering the string returned by setlocale()
or the structure returned by localeconv()
results in undefined behavior. See also undefined behavior 114 and 115 of Annex J of C99. Furthermore, C99 imposes no requirements on the contents of the string by setlocale()
. Consequently, a program should make no assumptions as to the string's internal contents or structure.
...
Altering the string returned by strerror()
results in undefined behavior. See also undefined behavior 174 of Annex J of C99.
Noncompliant Code Example (getenv()
)
...