Some funcitons functions return a pointer to a object that cannot be modified without causing undefined behavior. These functions include the standard getenv()
, setlocale()
, localeconv()
, and localeconvstrerror()
functions.
Wiki Markup |
---|
C99 \[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] defines {{getenv}} as follows: |
...
Altering the string returned by setlocale()
or the structure returned by localeconv()
results in undefined behavior.
Wiki Markup |
---|
Finally, C99 Section 7.21.6.2 \[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] 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 thestrerror
function.
Altering the string returned by strerror()
results in undefined behavior.
Noncompliant Code Example
...
Wiki Markup |
---|
\[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] Section 7.2011.41.51, "TheâThe {{getenvsetlocale}} function"functionâ, Section 7.11.12.1, âThe {{setlocalelocaleconv}} functionâ, Section 7.1120.2.1, âThe4.5, "The {{getenv}} function", Section 7.21.6.2 The {{localeconvstrerror}} functionâfunction \[[Open Group 04|AA. C References#Open Group 04]\] [getenv|http://www.opengroup.org/onlinepubs/000095399/functions/getenv.html], [setlocale|http://www.opengroup.org/onlinepubs/009695399/functions/setlocale.html], [localeconv|http://www.opengroup.org/onlinepubs/009695399/functions/localeconv.html] |
...